Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator::validateEqual returns always true if control value is empty array #257

Closed
woytam opened this issue Oct 8, 2020 · 0 comments
Closed
Milestone

Comments

@woytam
Copy link

woytam commented Oct 8, 2020

Version: master branch

Bug Description

When using addConditionOn() with MultichoiceControl and the value ($multichoicecontrol->getValue()) is empty array [], condition is always true.

Steps To Reproduce

$form->addCheckboxList('multi', 'Label', ['key' => ''])
	->setValue([]);

$form->addText('textName')
	->addConditionOn($form['multi'], $form::EQUAL, ['key'])
		->setRequired();

textName is always required.

Expected Behavior

textName required only if key from checkboxList is selected.

Possible Solution

The problem is in validator.php, where if control value ($value = $checkboxList->getValue()) returns empty array, it is considered as equal.
I have found problematic code in

foreach ((is_array($value) ? $value : [$value]) as $val) {

where foreach evaluates each return value. But in case of $value is empty array, foreach never occurs.

@dg dg added this to the v3.1 milestone Oct 8, 2020
@dg dg closed this as completed in 9f267bf Jan 18, 2021
dg added a commit that referenced this issue Jan 19, 2021
dg added a commit that referenced this issue Jan 19, 2021
dg added a commit that referenced this issue Jan 19, 2021
dg added a commit that referenced this issue Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants