Permalink
Browse files

ENHANCEMENT Defaulting to action_save button in ajaxSubmit() javascri…

…pt logic in CMS form

ENHANCEMENT Making ajax options overrideable in ajaxSubmit() javascript logic in CMS form

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92684 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 54a7beb commit 5f8a164d216377ba88b8c71e2bed7c02850aa87d @chillu chillu committed Nov 21, 2009
Showing with 10 additions and 5 deletions.
  1. +10 −5 javascript/LeftAndMain.EditForm.js
@@ -31,10 +31,13 @@
/**
* @param {DOMElement} button The pressed button (optional)
+ * @param {Function} callback Called in complete() handler of jQuery.ajax()
*/
- ajaxSubmit: function(button) {
+ ajaxSubmit: function(button, callback, ajaxOptions) {
+ // look for save button
+ if(!button) button = this.find('.Actions :submit[name=action_save]');
// default to first button if none given - simulates browser behaviour
- if(!button) button = this.find(':submit:first');
+ if(!button) button = this.find('.Actions :submit:first');
var self = this;
@@ -60,18 +63,20 @@
var formData = this.serializeArray();
// add button action
formData.push({name: $(button).attr('name'), value:'1'});
-
- $.ajax({
+ $.ajax($.extend({
url: this.attr('action'),
data: formData,
type: 'POST',
complete: function(xmlhttp, status) {
$(button).removeClass('loading');
+
+ if(callback) callback(xmlhttp, status);
+
// pass along original form data to enable old/new comparisons
self._loadResponse(xmlhttp.responseText, status, xmlhttp, formData);
},
dataType: 'html'
- });
+ }, ajaxOptions));
return false;
},

0 comments on commit 5f8a164

Please sign in to comment.