http://www.mediawiki.org/wiki/Special:Code/MediaWiki/76419
Revision: 76419 Author: yaron Date: 2010-11-10 00:14:20 +0000 (Wed, 10 Nov 2010) Log Message: ----------- Added handling for inputs rendered invisible by "show on select", so they don't mess up validation - based on patch submitted by Remco de Boer Modified Paths: -------------- trunk/extensions/SemanticForms/libs/SemanticForms.js Modified: trunk/extensions/SemanticForms/libs/SemanticForms.js =================================================================== --- trunk/extensions/SemanticForms/libs/SemanticForms.js 2010-11-09 23:35:24 UTC (rev 76418) +++ trunk/extensions/SemanticForms/libs/SemanticForms.js 2010-11-10 00:14:20 UTC (rev 76419) @@ -250,6 +250,7 @@ // checked - otherwise, hide it function showIfChecked(checkbox_inputs, div_id) { the_div = document.getElementById(div_id); + if ( the_div == null ) { return; } for (var i in checkbox_inputs) { checkbox = document.getElementById(checkbox_inputs[i]); if (checkbox != null && checkbox.checked) { @@ -266,11 +267,15 @@ eval(sfgShowOnSelectCalls[i]); } +function existsAndVisible(field) { + return (field && field.offsetWidth); +} + function validate_mandatory_field(field_id, info_id) { var field = document.getElementById(field_id); // if there's nothing at that field ID, ignore it - it's probably // a hidden field - if (field == null) { + if (!existsAndVisible(field)) { return true; } if (field.value.replace(/\s+/, '') == '') { @@ -303,7 +308,7 @@ var field = jQuery('input#' + field_id); // if there's nothing at that field ID, ignore it - it's probably // a hidden field - if (field == null) { + if (!existsAndVisible(field)) { return true; } // FIXME @@ -459,6 +464,18 @@ } scroll(0, 0); } + else + { + // Ensure that invisible fields, e.g. due to "show on select", + // are not submitted in the HTTP POST, by setting them to + // "disabled". Don't disable hidden fields, though (used e.g. + // for edit timestamp). + var inputs = jQuery("form.createbox").find("input, select, textarea"); + for (var i = 0; i < inputs.length; i++) { + input = inputs[i]; + input.disabled = input.type != "hidden" && !existsAndVisible(input); + } + } return (num_errors == 0); } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs