trying to validate a form with javascript with
$('#order-form').data('yiiActiveForm').submitting = true;
$('#order-form').yiiActiveForm('validate');
when form is
<?php $form = ActiveForm::begin(['id' => 'order-form', 'layout' => 'horizontal']); ?>
// somme fields
<?php ActiveForm::end() ?>
i expect the form to just validate the fields show error messages if any, but instead the form is submited
| Yii version | 2.0.10
| PHP version | 7.0.4
| Operating system | Windows
@massimans can you try code from current master branch?
@samdark same behavior in master for me, i will try to see whats going on in the javascript code
apparently yiiActiveForm.validate() calls updateInputs() witch will submit the form if you you set submitting to true an no error found in the form
What if you'll set it to false or omit it?
both cases no validation at all, input dont turn red or green an no event triggred
checked with
$('#order-form').on('afterValidate', function(e) {
console.log('afterValidate')
})
$('#order-form').on('beforeValidate', function(e) {
console.log('beforeValidate')
})
$('#order-form').on('beforeValidateAttribute', function(e) {
console.log('beforeValidateAttribute')
})
Thank you for the report, fixed
The issue is reopened now because the fix contained a regerssion
@SilverFire The bug appears again, I use dev-master version. In 2.0.12, 'validate' method doesn't work instead. Anyway, correct using of this method is impossible right now, isn't it?
I think problem is in this code:
if (forceValidate) {
$(this).data('yiiActiveForm').submitting = true;
}
It isn't necessary to submit form if I want just validate all its fields.
Mabye soonâ„¢ ?
@Shaeldon do you know how to fix it properly?