Validation if checked

I’m working with a kind of tabular input (user cannot add new items and each row is not a full model form). I’m following this guide to achieve data validation (doing it yourself part), but I have a problem:

  • When I submit the form, all fields go through validation and I just need to validate them if a row checkbox is cheked

How can I limit validation? Each row corresponds to a possible "Visit" model. In controller I create each Visit object and pass it to the view as an array of Visit objects. When I draw the form, I add a checkbox to each row. Form fields have names as [$i]datetime or [$i]commercial_agent_id.

Visit model has it’s own CRUD section that just works fine (this are Visit objects rapidly generated from another section of the admin…

I’ve managed it overriding validateMultiple method. There I check current scenario and post values (yes, it’s not very nice… I know) to decide if it must validate or not a row. I’ve avoided loadMultiple in controller because it’s just a mess with scenarios. I loop over rows and load one by one forcing scenario before load (to allow safe initialization) and reforcing again after validateMultiple.

It’s a bit weird (and dirty) but it works…