Commit e527f0bb28d40cdae66157cd3683ecb3d380d33c

Authored by Charl Joseph Mert
1 parent 1fadd3cf

Date format validation attempts to force the user to enter a date in the correct…

… format on a field where the user did not enter a date on a non-Required field.
Jira:KTS-4434

Committed by: Charl Joseph Mert
Reviewed by: Megan Watson
Showing 1 changed file with 8 additions and 13 deletions
plugins/ktcore/KTValidators.php
@@ -588,24 +588,19 @@ class KTDateValidator extends KTValidator { @@ -588,24 +588,19 @@ class KTDateValidator extends KTValidator {
588 function validate($data) { 588 function validate($data) {
589 $results = array(); 589 $results = array();
590 $errors = array(); 590 $errors = array();
591 -  
592 - // very simple if we're required and not present, fail  
593 - // otherwise, its ok.  
594 - $pMetaKey = array_keys($data);  
595 - $fieldId = str_replace('metadata_', '', $pMetaKey);  
596 - $oField = new DocumentField();  
597 - $oField->load($fieldId);  
598 -  
599 - if (!$oField->getIsMandatory()) {  
600 - return;  
601 - }  
602 - 591 +
603 $val = KTUtil::arrayGet($data, $this->sInputVariable); 592 $val = KTUtil::arrayGet($data, $this->sInputVariable);
604 - 593 +
605 if ($this->bTrim) { 594 if ($this->bTrim) {
606 $val = trim($val); 595 $val = trim($val);
607 } 596 }
608 597
  598 + // very simple if we're required and not present, fail
  599 + // otherwise, its ok.
  600 + if (empty($val) || $val == '') {
  601 + return;
  602 + }
  603 +
609 if (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $val, $parts)) 604 if (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $val, $parts))
610 { 605 {
611 //check weather the date is valid of not 606 //check weather the date is valid of not