I have got difficult form in yii2 view, where some fields show or hide. It decide from user field choises, select options in the form. I write this frontend logic with custom jquery file. All is ok. But when I submit form - hidden fields stay without validation and nothing is happend.How I can kill ofrontend validation, when fields are hiiden and switch on it, when fields are visible?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
For your Form, use whenClient:
And in ut_utils (JS):
You will need to add 'when' to validate serverside too you can add specific logic here or use a scenario to exclude attributes from being validated ...
You can try setting default values for attributes that aren't set:
more info here
You can also use conditional client-side validation with
"whenClient"
option when defining you validators:From the manual:
The
ActiveField
class has a propertyenableClientValidation
, you can simply set this property tofalse
if you want to disable clientValidation form some fields.To remove a field from validation:
To add a field to validation list:
And don't forget conditional validation in your model. More info
To disable client side validation. Begin your active form like this.
You can set your active field using this code: (not
active record
,activefield
exactly)