Onsubmit Twice

Hi guys.

Speaking about this https://github.com/yiisoft/yii2/issues/1384

how am I supposed to write my own onsubmit handlers (for example, complex ajax submit) so that it can be fired only once and right after form validation?

In your handler, you can check $form.yiiActiveForm(‘data’).validated to see if it is true and submit the data if so.

Cool, thanks!!

Hmm, not that cool.

Seems like I can’t.

submitForm: function () {

    var $form = $(this),

        data = $form.data('yiiActiveForm');

    if (data.validated) {

        // continue submitting the form since validation passes

        data.validated = false;

        return true;




data.validated is always false in my callback.

And also there’s no $form.yiiActiveForm if no client validation is involved, so this should be checked also, which is kinda painful.

Is there any particular reason to fire onsubmit event second time?..

We don’t have control of the first time because we need it to trigger the validation. [size=2]The second time is needed so that the form can be submitted. Do you have good suggestion to avoid submitting twice?[/size]



[size=2]I just removed the line data.validated=false. Could you try again?[/size]

It works now, thanks.

I hope this will not cause any side-effects.