yii-jquery
yii-jquery copied to clipboard
yii.activeForm.js refactoring/enhancements
Originally suggested by @DmLapin here: https://github.com/yiisoft/yii2/issues/10549#issuecomment-227441454
There are few potential places for changes, but it can break compatibility (may be it could be included in 2.1 milestone):
- validate() should validate regardless of field.state or form.submitting and trigger appropriate events like before/afterValidate
- updateInputs() should work only with error messages, as it's doc says and should not watch for internal form state and should not submit form by self.
- my logic tells me that validate() method should call validateAttribute() during its operation but not vice versa.
- replace status = 1 / 2 / 3 (if activeForm really needs it) with comprehensible variables like STATUS_VALIDATED / STATUS_WAIT_FOR_VALIDATION / ...
But at current moment at least validate() and updateInputs() methods should be fixed to perform validation properly and trigger afterValidate event in case of manual call.
If things are being enhanced it would be nice if validateAttribute could return a promise so you can have a complete callback.
e.g
$('#my-form').yiiActiveForm('validateAttribute', 'attribute').done(validated => { });