This came up today as something that is a very basic requirement when developing complex forms, but there was no way built in to Yii to handle it quickly and consistently across multiple models, so I created a custom validator for it. I hope it helps others to move forward quickly with their complex form development ;)
The need was that when a specific field was set or a specific value was selected for a field, additional fields would become required.
The solution? ChildrenRequiredValidator
http://www.yiiframework.com/extension/childrenrequiredvalidator/
Any feedback or suggestions are more than welcome!
Showing posts with label validation. Show all posts
Showing posts with label validation. Show all posts
Tuesday, August 9, 2011
Wednesday, March 31, 2010
Posting with multiple models
I spent a good bit of time trying to figure out how to render multiple models in a form and have them each validate properly.
Knowing the solution, it seems quite obvious, but it took a while to track down the proper syntax.
In this example I have a custom CForm which contains a few different $model properties, in addition to the base form data.
To call the validation on multiple models in the form, simply modify any calls of
Knowing the solution, it seems quite obvious, but it took a while to track down the proper syntax.
In this example I have a custom CForm which contains a few different $model properties, in addition to the base form data.
To call the validation on multiple models in the form, simply modify any calls of
CActiveForm::validate($model);to use an array of models as the first parameter as such:
CActiveForm::validate( array($model, $model->subModel, $model->subModel2) );
Labels:
ajax,
CActiveForm,
models,
post,
validation,
yii
Subscribe to:
Posts (Atom)