(07-28-2016, 12:03 PM)PaulD Wrote: Hi,
I think the way you are trying to do it is going to be difficult anyway, because if you want to show the individual form error messages you will have to do it via js updating the individual message fields. Which means detecting the individual errors and identifying who they are for, which is going to be a very complex js response decoding.
I would suggest doing this via a multi step form, or having all your fields perhaps in tabs labelled vehicle 1, vehicle 2 etc. with vehicle 2 and above being optional. Alternatively you can have two submit buttons, one for save vehicle and add another or save vehicle and finish. Or have a screen showing vehicles submitted so far, with a button for adding a vehicle (like addresses in an address book).
Alternatively, inserting this sort of code via javascript, means you can also update a hidden field indicating how many vehicles have been selected, by incrementing the hidden form value. So when you sumbit it, you know how many vehicles you are expecting.
Or, have all the fields for all 5 vehicles in the form, but put the four optional ones in divs set as display none. Then a simple piece of js could remove the style one by one until all five are required. In that way you are submitting the entire form every time, except that only the required vehicles are being validated. Again when you show the form your controller will set how many to show by default.
There are so many ways to do this, it really depends on how you want the UI to behave. For ease of identifying fields, just make sure they all have a unique name, so you have vehicle_name_1, vehicle_name_2 etc. The only reason the script you are basing this on is doing them as array names is for ease of collecting the data via js, not for the ease of implementing error messages upon ajax response.
What it appears that you are struggling with is the way the script you have chosen has been written. Since this is relatively straight forward to do from scratch with JS, perhaps you could write your own version to do the same thing but name all the fields more appropriately.
Sorry if that is not much help,
Paul.
PS you may want to issue a deadline may be missed warning to whoever your deadline is with. Or if it is just you said "I will have it done by wednesday", let them know it is taking longer than expected. I find blaming IE bugs is quite handy for this kind of situation :-)
Thanks Paul. the thing is there is no fix amount of vehicles, think person "X" have only 1 vehicle then there is person "Y" whom own 2 or more my clients requirment is there should be an option to add multiple vehicles for a single person. that's why i choose the way i described in the main post.
Thanks for the suggestions, i really don't know what to do.....