diff --git a/src/Forms/Validator.php b/src/Forms/Validator.php index 092e7f492..af35ff1fe 100644 --- a/src/Forms/Validator.php +++ b/src/Forms/Validator.php @@ -113,6 +113,10 @@ public static function validateEqual(Control $control, $arg): bool foreach ($values as $val) { foreach ($args as $item) { + if ($item instanceof \BackedEnum) { + $item = $item->value; + } + if ((string) $val === (string) $item) { continue 2; } diff --git a/tests/Forms/Controls.BaseControl.enum.phpt b/tests/Forms/Controls.BaseControl.enum.phpt new file mode 100644 index 000000000..bee011224 --- /dev/null +++ b/tests/Forms/Controls.BaseControl.enum.phpt @@ -0,0 +1,39 @@ +addText('text'); + $input->setValue(TestEnum::CASE_1->value); + + Assert::true(Validator::validateEqual($input, TestEnum::CASE_1)); + Assert::true(Validator::validateEqual($input, 'case 1')); + Assert::false(Validator::validateEqual($input, TestEnum::CASE_2)); + Assert::false(Validator::validateEqual($input, 1)); +});