Skip to content

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

@woytam

Description

@woytam

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions