Open ne0-cz opened 1 year ago
I think this will be enough:
$form->onValidate[] = function (array $values) {
$count = count($values['multiplier']);
};
@MartkCz Unfortunately that's not enough. I use the multiplier to get names of people. I also give the user a choice how many rooms to put those people in. It makes sense to only show reasonable number of rooms (e.g. I can't put 8 people in 1 room) so I want to enable/disable some choices based on the number of people in the multiplier.
So my default is 1 person and only 1 room enabled. When I do the enable/disable in onValidate
it seems to work until I submit the form with number of rooms different than default (e.g 2): the control fails (2 is disabled), onValidate is called (and 2 is enabled only now): and since the control is already invalidated the whole form fails to submit...
I'm unable to use number of multiplier items for validation. I'd like to validate other parts of the form based on current number of items in the multiplier (it seemed like the method
getCopyNumber
might be the one but it just returns0
), e.g. some field is mandatory when there's more than 3 items.It would also be helpful to have number of the current item itself as part of the validation message, e.g. "You need to fill the 3. item's name" - I can't really access the multiplier itself in the defining function, let alone get the current number.
Thanks!