Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

How i can get acces to form element in .error() method? #205

Closed
kulakowka opened this Issue Jun 7, 2012 · 2 comments

Comments

Projects
None yet
3 participants

I need get acces to form element in .error() method? but i dont know how?

What can I do as it may be so?

$('#form').ajaxForm({
        dataType: 'json',
        url: '/json/settings/profile/',
        beforeSubmit: function(formData, jqForm, options){

        },
        error: function( jqForm ){

        },
        success: function(json, statusText, xhr, jqForm){

        }
    });

The documentation does not say about it.

Collaborator

malsup commented Jun 7, 2012

You can do something like this:

$('#form').ajaxForm({
    dataType: 'json',
    url: '/json/settings/profile/',
    form: $('#form'),  // add form as property to options object
    beforeSubmit: function(formData, jqForm, options){

    },
    error: function( jqForm ){
        var jqForm = this.form;  // access form from 'this' context

    },
    success: function(json, statusText, xhr, jqForm){

    }
});

@malsup malsup closed this Jun 7, 2012

Contributor

freejosh commented Jan 11, 2013

What about when the selector has multiple forms? Or when using the delegation option?

You're adding the form element to the end of the arguments of the success callback, why not do the same for error and complete?

For now I'm able to select the current form using:

error: function() {
    var form = $('form[action="'+this.url+'"]);
}

@freejosh freejosh pushed a commit to freejosh/form that referenced this issue Jan 21, 2013

Josh Freeman Added access to $form in complete and error callbacks, as per my comm… e59fde4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment