Hi.
I need an user interface where user can choose from 4 tabs, fill in only one of it and submit.
Tabs data are similar, one have title, image, the other have title and text, etc., so i was trying to make it single model. (CFormModel for later processing)
I use yiibooster, so i have chosen TbTabs.
I have done some experiments and i’m nearly complete.
My first version was one form and one model + tbtab with form fields in each tab (tabs using separate views using renderPartial), that was not a good solution, there were problems with validation, as every tab need to be independent in validation, yet, all the tabs must be in one page in a tabbed manner.
So now each tab is an independent form, i can still easily change the tab, but i’m not sure if i should try to make it with one model.
With the server side validation it is no problem, but the thing is, after post i go back to the posted form, so i’m setting the selected tab using a hidden field with tab name, the problem is with the client validation.
To be specific, if all 4 forms are on one page using one model, ajax validation will work correctly as it is POST so i can use a scenario, but to render client validation so required fields have red asterisks i need to make it required also without a scenario if using one model (and one instance) and if i do so ajax validation will also validate it and produce validation for fields not in current form.
So i was thinking about my options, i want to keep it as simple as possible and maintainable, so i have some questions:
-
Should i just still use one model, but instead make a default scenario ‘def’, so that there would be no rules without scenario and this way i can explicit set what i want to validate? Client and ajax validation will work good then.
-
Or maybe it is better make 4 models for each form independently? But then i will copy near the same code(very similar fields) and also i think it will complicate the controller code, but there will be clear model for every form.
-
Does it has any sense to enable both client and ajax validation? Should i ajax validate only more complex fields (check url points to existing file etc.) using validate attributes?
-
Any other ideas? Maybe someone has such problem and will share how it was resolved?