I have a active form and I am trying to validate it using the script written below :
jQuery("#form").yiiActiveForm("submitForm");
The problem is, the script always returns false. But when I call it second time with some delay, it returns true.
jQuery("#form").yiiActiveForm("submitForm");
setTimeout(function () {
if (jQuery("#form").yiiActiveForm("submitForm")) {
//ajax call...
}
}, 300);
My question is, how does validation works in yii2 ? And is there a better way to validate active forms in js?
When I use
jQuery("#form").yiiActiveForm("submitForm");
beforeSubmit handler is called.
$('#form').on('beforeSubmit', function (e) {
alert('message');
});
Does beforeSubmit automatically validates the form?
Simple
You should try this
Changes