Can the RangeValidator for an Array show which value fails?

Hi There,
I am using a range validator with allowArray.
If one of the items of the Array is failing, the error message does not say which ones.

If I use this:
$validator = [‘value’, ‘in’, ‘range’ => $range, ‘allowArray’ => true, ‘message’ => ‘{value} failed’];
then the displayed message is:
array() failed.

Is there a way to achieve this?

Hi @gb5256,

The following is the source code of RangeValidator::validateValue():

It uses ArrayHelper::isSubset() to check the values.
So, there’s no way to tell which value failed when allowArray is true.

You would want to write your own custom validator to satisfy your needs.

1 Like