0

I am having trouble in understanding jQuery custom events and namespaces, In the below code I can see that the the custom event login:submit is being triggered but nowhere I can see a handler function for handling this event, can anyone help me understand what the below block of code is doing

 login: function () {
    $('form.login').submit(function (e) {
        var form = $(this);
        e.preventDefault();
        var url = form.attr('action');
        form.spinner().start();
        $('form.login').trigger('login:submit', e);
        $.ajax({
            url: url,
            type: 'post',
            dataType: 'json',
            data: form.serialize(),
            success: function (data) {
                form.spinner().stop();
                if (!data.success) {
                    formValidation(form, data);
                    $('form.login').trigger('login:error', data);
                } else {
                    $('form.login').trigger('login:success', data);
                    location.href = data.redirectUrl;
                }
            },
            error: function (data) {
                if (data.responseJSON.redirectUrl) {
                    window.location.href = data.responseJSON.redirectUrl;
                } else {
                    $('form.login').trigger('login:error', data);
                    form.spinner().stop();
                }
            }
        });
        return false;
    });
}
Faizen
  • 21
  • 1
  • Not shown in code in question but somewhere there would need to be something like `$('form').on('login:submit', func...`. Perhaps it is part of some library being used? – charlietfl May 21 '21 at 21:56
  • That is the irony I have searched the entire codebase but I can't find it, thatswhy I am totally annoyed – Faizen May 22 '21 at 08:31
  • Perhaps it was removed then. Triggering an event that has no listeners shouldn't have any side effects – charlietfl May 22 '21 at 11:13

0 Answers0