Bug Tracker

Changeset 5359

Show
Ignore:
Timestamp:
04/30/08 00:19:42 (7 months ago)
Author:
malsup
Message:

Fix for ticket 2752 (don't submit when no element is selected)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/form/jquery.form.js

    r4860 r5359  
    11/* 
    22 * jQuery Form Plugin 
    3  * version: 2.07 (03/04/2008) 
     3 * version: 2.08 (04/29/2008) 
    44 * @requires jQuery v1.2.2 or later 
    55 * 
     
    1111 * Revision: $Id$ 
    1212 */ 
    13  (function($) { 
     13(function($) { 
     14 
    1415/** 
    1516 * ajaxSubmit() provides a mechanism for submitting an HTML form using AJAX. 
     
    178179 */ 
    179180$.fn.ajaxSubmit = function(options) { 
     181    // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) 
     182    if (!this.length) { 
     183        log('ajaxSubmit: skipping submit process - no element selected'); 
     184        return this; 
     185    } 
     186 
    180187    if (typeof options == 'function') 
    181188        options = { success: options }; 
     
    190197    var veto = {}; 
    191198    this.trigger('form-pre-serialize', [this, options, veto]); 
    192     if (veto.veto) return this; 
     199    if (veto.veto) { 
     200        log('ajaxSubmit: submit vetoed via form-pre-serialize trigger'); 
     201        return this; 
     202   } 
    193203 
    194204    var a = this.formToArray(options.semantic); 
     
    200210 
    201211    // give pre-submit callback an opportunity to abort the submit 
    202     if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) return this; 
     212    if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) { 
     213        log('ajaxSubmit: submit aborted via beforeSubmit callback'); 
     214        return this; 
     215    }     
    203216 
    204217    // fire vetoable 'validate' event 
    205218    this.trigger('form-submit-validate', [a, this, options, veto]); 
    206     if (veto.veto) return this; 
     219    if (veto.veto) { 
     220        log('ajaxSubmit: submit vetoed via form-submit-validate trigger'); 
     221        return this; 
     222    }     
    207223 
    208224    var q = $.param(a); 
     
    867883}; 
    868884 
     885// helper fn for console logging 
     886// set $.fn.ajaxSubmit.debug to true to enable debug logging 
     887function log() { 
     888    if ($.fn.ajaxSubmit.debug && window.console && window.console.log) 
     889        window.console.log('[jquery.form] ' + Array.prototype.join.call(arguments,'')); 
     890}; 
     891 
    869892})(jQuery);