Index: trunk/extensions/SemanticForms/libs/SemanticForms.js |
— | — | @@ -221,8 +221,8 @@ |
222 | 222 | function setupSF() { |
223 | 223 | |
224 | 224 | jQuery("#sfForm").data("SemanticForms",{ |
225 | | - initFunctions : new Array(), |
226 | | - validationFunctions : new Array |
| 225 | + initFunctions : [], |
| 226 | + validationFunctions : [] |
227 | 227 | }); |
228 | 228 | |
229 | 229 | } |
— | — | @@ -232,6 +232,8 @@ |
233 | 233 | // More than one method may be registered for one input by subsequent calls to |
234 | 234 | // SemanticForms_registerInputValidation. |
235 | 235 | // |
| 236 | +// Validation functions and their data are stored in a numbered array |
| 237 | +// |
236 | 238 | // @param valfunction The validation functions. Must take a string (the input's id) and an object as parameters |
237 | 239 | // @param param The parameter object given to the validation function |
238 | 240 | jQuery.fn.SemanticForms_registerInputValidation = function(valfunction, param) { |
— | — | @@ -242,11 +244,8 @@ |
243 | 245 | setupSF(); |
244 | 246 | } |
245 | 247 | |
246 | | - if ( ! jQuery("#sfForm").data("SemanticForms").validationFunctions[this.attr("id")] ) { |
247 | | - jQuery("#sfForm").data("SemanticForms").validationFunctions[this.attr("id")] = new Array(); |
248 | | - } |
249 | | - |
250 | | - jQuery("#sfForm").data("SemanticForms").validationFunctions[this.attr("id")].push({ |
| 248 | + jQuery("#sfForm").data("SemanticForms").validationFunctions.push({ |
| 249 | + input : this.attr("id"), |
251 | 250 | valfunction : valfunction, |
252 | 251 | parameters : param |
253 | 252 | }); |
— | — | @@ -260,6 +259,8 @@ |
261 | 260 | // SemanticForms_registerInputInit. This method also executes the initFunction |
262 | 261 | // if the element referenced by /this/ is not part of a multipleTemplateStarter. |
263 | 262 | // |
| 263 | +// Initialization functions and their data are stored in a associative array |
| 264 | +// |
264 | 265 | // @param initFunction The initialization function. Must take a string (the input's id) and an object as parameters |
265 | 266 | // @param param The parameter object given to the initialization function |
266 | 267 | // @param noexecute If set, the initialization method will not be executed here |
— | — | @@ -556,19 +557,19 @@ |
557 | 558 | // call registered validation functions |
558 | 559 | var sfdata = jQuery("#sfForm").data('SemanticForms'); |
559 | 560 | |
560 | | - if (sfdata) { // found data object? |
| 561 | + if ( sfdata && sfdata.validationFunctions.length > 0 ) { // found data object? |
561 | 562 | |
562 | 563 | // for every registered input |
563 | | - for ( var id in sfdata.validationFunctions ) { |
| 564 | + for ( var i = 0; i < sfdata.validationFunctions.length; ++i ) { |
564 | 565 | |
565 | 566 | // if input is not part of multipleTemplateStarter |
566 | | - if ( jQuery("#" + id).closest(".multipleTemplateStarter").length == 0 ) { |
| 567 | + if ( jQuery("#" + sfdata.validationFunctions[i].input).closest(".multipleTemplateStarter").length == 0 ) { |
567 | 568 | |
568 | | - // Call every validation method for this input. |
569 | | - for ( var i in sfdata.validationFunctions[id]) { |
570 | | - if (! sfdata.validationFunctions[id][i].valfunction(id, sfdata.validationFunctions[id][i].parameters) ) |
571 | | - num_errors += 1; |
572 | | - } |
| 569 | + if (! sfdata.validationFunctions[i].valfunction( |
| 570 | + sfdata.validationFunctions[i].input, |
| 571 | + sfdata.validationFunctions[i].parameters) |
| 572 | + ) |
| 573 | + num_errors += 1; |
573 | 574 | } |
574 | 575 | } |
575 | 576 | } |
— | — | @@ -640,12 +641,15 @@ |
641 | 642 | // For every validation method for the |
642 | 643 | // input with ID old_id, register it |
643 | 644 | // for the new input. |
644 | | - for ( i in sfdata.validationFunctions[old_id] ) { |
| 645 | + for ( var i = 0; i < sfdata.validationFunctions.length; ++i ) { |
645 | 646 | |
646 | | - jQuery(this).SemanticForms_registerInputValidation( |
647 | | - sfdata.validationFunctions[old_id][i].valfunction, |
648 | | - sfdata.validationFunctions[old_id][i].parameters |
649 | | - ); |
| 647 | + if ( sfdata.validationFunctions[i].input == old_id ) { |
| 648 | + |
| 649 | + jQuery(this).SemanticForms_registerInputValidation( |
| 650 | + sfdata.validationFunctions[i].valfunction, |
| 651 | + sfdata.validationFunctions[i].parameters |
| 652 | + ); |
| 653 | + } |
650 | 654 | } |
651 | 655 | } |
652 | 656 | } |
— | — | @@ -691,7 +695,7 @@ |
692 | 696 | // Remove the encompassing div for this instance. |
693 | 697 | jQuery(this).closest(".multipleTemplateInstance") |
694 | 698 | .fadeOut('fast', function() { jQuery(this).remove(); }); |
695 | | - }); |
| 699 | + }); |
696 | 700 | |
697 | 701 | // Enable autocompletion |
698 | 702 | new_div.find('.autocompleteInput').attachAutocomplete(); |