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

Using number of items in multiplier in validation #81

Open
ne0-cz opened this issue Feb 20, 2023 · 2 comments
Open

Using number of items in multiplier in validation #81

ne0-cz opened this issue Feb 20, 2023 · 2 comments

Comments

@ne0-cz
Copy link

ne0-cz commented Feb 20, 2023

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 returns 0), 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!

@MartkCz
Copy link
Member

MartkCz commented Feb 20, 2023

I think this will be enough:

$form->onValidate[] = function (array $values) {
    $count = count($values['multiplier']);
};

@ne0-cz
Copy link
Author

ne0-cz commented Feb 22, 2023

@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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants