lib/public/javascripts/edifice/form.js in edifice-0.6.5 vs lib/public/javascripts/edifice/form.js in edifice-0.6.6
- old
+ new
@@ -26,10 +26,12 @@
$form.initialize();
}
var methods = {
initialize: function() {
+ // I don't know why, but FF seems to helpful remember that these are disabled
+ this.submits().removeAttr('disabled');
this.prepare_validators();
this.prepare_submit();
},
prepare_validators: function() {
@@ -45,21 +47,20 @@
$form.set_validator($(this), $(this).attr('data-widget-validator'));
});
// listen to validator
this.fields().live('change.ajax_form focusout.ajax_form', function() {
- $form.validate($(this));
+ if ($form.validate($(this)) === false) { $form.trigger('invalid', [$form, $(this)]); }
});
},
prepare_submit: function() {
var $form = this;
this.submit(function(event) {
// do pre-submit validations
if (!$form.valid()) {
- $form.trigger('invalid');
- $form.focus_error();
+ $form.invalid();
return false; // we are done.
}
$form.submits().attr('disabled', true); // disable submit buttons
@@ -71,37 +72,37 @@
dataType: $form.settings.dataType,
data: $.param($form.serializeArray()),
cache: false,
error: function (x, t, e) { $form.error(x, t, e); },
success: function (data, status) {
- $form.trigger('success', data, status);
+ $form.trigger('success', [data, status, $form]);
},
complete: function (request, text_status) {
- $form.trigger('complete', request, text_status);
+ $form.trigger('complete', [request, text_status, $form]);
$form.submits().removeAttr('disabled');
}
});
event.preventDefault();
- return false;
}
});
},
- // focus the first error
- focus_error: function() {
+ invalid: function() {
+ // focus the first error
this.error_fields().eq(0).focus();
+ this.trigger('invalid', [this]);
},
error: function(request, text_status, error) {
this.trigger('error', request, status, error);
// handle the different possible errors that we can see
if (request.status >= 400 && request.status < 500) {
// CLIENT ERROR -- server-side validation failed.
- this.trigger('client_error', request, status, error);
+ this.trigger('client_error', [request, status, error, this]);
// if data is html, we replace this content of the form with the content
// of the form that we've just received back
if (this.settings.dataType === 'html') {
// wrap in a div incase there are a bunch of floating elements, pull the form out
@@ -115,13 +116,13 @@
this.set_errors($.parseJSON(request.responseText));
} else {
throw "Don't know how to handle dataType " + this.settings.dataType;
}
- this.focus_error();
+ this.invalid();
} else if (request.status >= 500 && request.status < 600) {
// a SERVER ERROR -- something unrecoverable happened on the server
- this.trigger('server_error', request, status, error);
+ this.trigger('server_error', [request, status, error, this]);
// we aren't going to do anything here.
// FIXME: we should probably have a way to set this behaviour at the application level.
// for instance, you probably just want to redirect to somewhere, or show a dialog,
// or popup something or.....?
\ No newline at end of file