r80431 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80430‎ | r80431 | r80432 >
Date:00:55, 17 January 2011
Author:foxtrott
Status:deferred
Tags:
Comment:
bugfix: validation methods could not be iterated
Modified paths:
  • /trunk/extensions/SemanticForms/libs/SemanticForms.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/libs/SemanticForms.js
@@ -221,8 +221,8 @@
222222 function setupSF() {
223223
224224 jQuery("#sfForm").data("SemanticForms",{
225 - initFunctions : new Array(),
226 - validationFunctions : new Array
 225+ initFunctions : [],
 226+ validationFunctions : []
227227 });
228228
229229 }
@@ -232,6 +232,8 @@
233233 // More than one method may be registered for one input by subsequent calls to
234234 // SemanticForms_registerInputValidation.
235235 //
 236+// Validation functions and their data are stored in a numbered array
 237+//
236238 // @param valfunction The validation functions. Must take a string (the input's id) and an object as parameters
237239 // @param param The parameter object given to the validation function
238240 jQuery.fn.SemanticForms_registerInputValidation = function(valfunction, param) {
@@ -242,11 +244,8 @@
243245 setupSF();
244246 }
245247
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"),
251250 valfunction : valfunction,
252251 parameters : param
253252 });
@@ -260,6 +259,8 @@
261260 // SemanticForms_registerInputInit. This method also executes the initFunction
262261 // if the element referenced by /this/ is not part of a multipleTemplateStarter.
263262 //
 263+// Initialization functions and their data are stored in a associative array
 264+//
264265 // @param initFunction The initialization function. Must take a string (the input's id) and an object as parameters
265266 // @param param The parameter object given to the initialization function
266267 // @param noexecute If set, the initialization method will not be executed here
@@ -556,19 +557,19 @@
557558 // call registered validation functions
558559 var sfdata = jQuery("#sfForm").data('SemanticForms');
559560
560 - if (sfdata) { // found data object?
 561+ if ( sfdata && sfdata.validationFunctions.length > 0 ) { // found data object?
561562
562563 // for every registered input
563 - for ( var id in sfdata.validationFunctions ) {
 564+ for ( var i = 0; i < sfdata.validationFunctions.length; ++i ) {
564565
565566 // 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 ) {
567568
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;
573574 }
574575 }
575576 }
@@ -640,12 +641,15 @@
641642 // For every validation method for the
642643 // input with ID old_id, register it
643644 // for the new input.
644 - for ( i in sfdata.validationFunctions[old_id] ) {
 645+ for ( var i = 0; i < sfdata.validationFunctions.length; ++i ) {
645646
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+ }
650654 }
651655 }
652656 }
@@ -691,7 +695,7 @@
692696 // Remove the encompassing div for this instance.
693697 jQuery(this).closest(".multipleTemplateInstance")
694698 .fadeOut('fast', function() { jQuery(this).remove(); });
695 - });
 699+ });
696700
697701 // Enable autocompletion
698702 new_div.find('.autocompleteInput').attachAutocomplete();