Commit e287e106 authored by Ad Schellevis's avatar Ad Schellevis

(mvc) improve ModelRelation validation

parent 212a5e48
......@@ -29,7 +29,7 @@
*/
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\Regex;
use Phalcon\Validation\Validator\InclusionIn;
/**
* Class ModelRelationField defines a relation to another entity within the model, acts like a select item.
......@@ -102,25 +102,16 @@ class ModelRelationField extends BaseField
*/
public function getValidators()
{
// build validation mask
$validationMask = '(';
$countid = 0 ;
foreach (self::$internalOptionList as $key => $value) {
if ($countid > 0) {
$validationMask .= '|';
}
$validationMask .= $key ;
$countid++;
}
$validationMask .= ')';
if ($this->internalValidationMessage == null) {
$msg = "option not in list" ;
$msg = "option not in list";
} else {
$msg = $this->internalValidationMessage;
}
if (($this->internalIsRequired == true || $this->internalValue != null) && $validationMask != null) {
return array(new Regex(array('message' => $msg,'pattern'=>trim($validationMask))));
if (($this->internalIsRequired == true || $this->internalValue != null) &&
count(self::$internalOptionList) > 0
) {
return array(new InclusionIn(array('message' => $msg, 'domain' => array_keys(self::$internalOptionList))));
} else {
// empty field and not required, skip this validation.
return array();
......
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