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 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\Regex;
use Phalcon\Validation\Validator\PresenceOf;
/**
* Class TextField
......@@ -60,16 +61,17 @@ class TextField extends BaseField
*/
public function getValidators()
{
$validators = array() ;
if ($this->internalValidationMessage == null) {
$msg = "text validation error" ;
} else {
$msg = $this->internalValidationMessage;
}
if (($this->internalIsRequired == true || $this->internalValue != null) && $this->internalMask != null) {
return array(new Regex(array('message' => $msg,'pattern'=>trim($this->internalMask))));
} else {
// empty field and not required, skip this validation.
return array();
if ($this->internalIsRequired && empty($this->internalValue)) {
$validators[] = new PresenceOf(array('message' => $msg)) ;
} elseif ($this->internalValue != null && $this->internalMask != null) {
$validators[] = array(new Regex(array('message' => $msg,'pattern'=>trim($this->internalMask))));
}
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