D
D
Dmitry Kim2016-07-02 12:01:28
JavaScript
Dmitry Kim, 2016-07-02 12:01:28

How to find out which form submit was clicked?

There is a form. There is a LaddaButtons plugin lab.hakim.se/ladda . There is a javascript code:

// Form submit
    $(document).on('beforeValidate', 'form', function (event, messages, deferreds) {
        var btn = $(this).find('[type=submit]');
        btn.ladda();
        btn.ladda('start');
    }).on('afterValidate', 'form', function (event, messages, errorAttributes) {
        if (errorAttributes.length) {
            var btn = $(this).find('[type=submit]');
            btn.ladda('stop');
            alert('Сначала исправьте ошибки формы!');
        }
    }).on('beforeSubmit', 'form', function (event) {
        var btn = $(this).find('[type=submit]');
        btn.ladda('start');
    });
    Ladda.bind('.ladda-button');

For those who do not want to follow the link, I will explain how it works: when you click on the submit form, the submit button is deactivated and the wheel is spinning inside it.
Everything was fine, but I did not take into account this: when there are several submits in the form, then all of them are animated in such a way that, as it were, is not quite correct. It would be correct to deactivate all submissions, but turn the wheel only on the submit that was clicked.
How to get the button that was clicked in an yii.activeForm.jsevent ?beforeValidate

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Arutyunov, 2016-07-02
@arutyunov

Something is wrong with your interface if there is more than 1 submit in 1 form.

N
Nikita, 2016-07-02
@bitver

As an option, replace your beforeValidate with an event on the button, which will do everything you need before validation, and then call$('#contact-form').yiiActiveForm('validate');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question