Commit ec0dddbe authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(mvc) fix is required on TextField

parent b553b009
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
namespace OPNsense\Base\FieldTypes; namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\Regex; use Phalcon\Validation\Validator\Regex;
use Phalcon\Validation\Validator\PresenceOf;
/** /**
* Class TextField * Class TextField
...@@ -60,16 +61,17 @@ class TextField extends BaseField ...@@ -60,16 +61,17 @@ class TextField extends BaseField
*/ */
public function getValidators() public function getValidators()
{ {
$validators = array() ;
if ($this->internalValidationMessage == null) { if ($this->internalValidationMessage == null) {
$msg = "text validation error" ; $msg = "text validation error" ;
} else { } else {
$msg = $this->internalValidationMessage; $msg = $this->internalValidationMessage;
} }
if (($this->internalIsRequired == true || $this->internalValue != null) && $this->internalMask != null) { if ($this->internalIsRequired && empty($this->internalValue)) {
return array(new Regex(array('message' => $msg,'pattern'=>trim($this->internalMask)))); $validators[] = new PresenceOf(array('message' => $msg)) ;
} else { } elseif ($this->internalValue != null && $this->internalMask != null) {
// empty field and not required, skip this validation. $validators[] = array(new Regex(array('message' => $msg,'pattern'=>trim($this->internalMask))));
return array();
} }
return $validators;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment