views:

352

answers:

3

I'm trying to access my form object inside of ajaxForm's error method:

$('#foo').ajaxForm({
  error: function(){
    // where's my $('#foo') object?
  }
});

error can take 3 params, but none of them are the form object, also this returns the url, but again no form.

Any suggestions?

A: 

Does this not work? I.e.,

$('#foo').ajaxForm({
  error: function(){
    alert($(this).attr('name'));
  }
});
inkedmn
@indedmn: Looks like the this keyword in the callback refers to the URL. See the OP...
David Andres
+1  A: 

Tricky, why not use:

var myForm = $("#foo");

myForm.ajaxForm({
 error: function(){
  myForm.//whatever
 }
});

If there is another way, I'd love to know myself.

David Andres
It's nice that success/beforeSubmit all have direct access to the form object and kinda annoying that error isn't consistent with that.
crankharder
@crankharder: You're right, it can get very confusing.
David Andres
A: 

If you read the tab 'Working with Fields' in that plugin's docs, I think you'll find your answer.

For performance, you should probably store a reference to the form before you bind the ajaxForm.

$(document).ready(function() {
    $foo = $('#foo');
    $foo.ajaxForm({
        error: function() {
            alert($('#fieldId', $foo).fieldValue()[0]);
        }
    });
});
great_llama