r76419 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76418‎ | r76419 | r76420 >
Date:00:14, 10 November 2010
Author:yaron
Status:deferred
Tags:
Comment:
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) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/libs/SemanticForms.js
@@ -250,6 +250,7 @@
251251 // checked - otherwise, hide it
252252 function showIfChecked(checkbox_inputs, div_id) {
253253 the_div = document.getElementById(div_id);
 254+ if ( the_div == null ) { return; }
254255 for (var i in checkbox_inputs) {
255256 checkbox = document.getElementById(checkbox_inputs[i]);
256257 if (checkbox != null && checkbox.checked) {
@@ -266,11 +267,15 @@
267268 eval(sfgShowOnSelectCalls[i]);
268269 }
269270
 271+function existsAndVisible(field) {
 272+ return (field && field.offsetWidth);
 273+}
 274+
270275 function validate_mandatory_field(field_id, info_id) {
271276 var field = document.getElementById(field_id);
272277 // if there's nothing at that field ID, ignore it - it's probably
273278 // a hidden field
274 - if (field == null) {
 279+ if (!existsAndVisible(field)) {
275280 return true;
276281 }
277282 if (field.value.replace(/\s+/, '') == '') {
@@ -303,7 +308,7 @@
304309 var field = jQuery('input#' + field_id);
305310 // if there's nothing at that field ID, ignore it - it's probably
306311 // a hidden field
307 - if (field == null) {
 312+ if (!existsAndVisible(field)) {
308313 return true;
309314 }
310315 // FIXME
@@ -459,6 +464,18 @@
460465 }
461466 scroll(0, 0);
462467 }
 468+ else
 469+ {
 470+ // Ensure that invisible fields, e.g. due to "show on select",
 471+ // are not submitted in the HTTP POST, by setting them to
 472+ // "disabled". Don't disable hidden fields, though (used e.g.
 473+ // for edit timestamp).
 474+ var inputs = jQuery("form.createbox").find("input, select, textarea");
 475+ for (var i = 0; i < inputs.length; i++) {
 476+ input = inputs[i];
 477+ input.disabled = input.type != "hidden" && !existsAndVisible(input);
 478+ }
 479+ }
463480 return (num_errors == 0);
464481 }
465482

Follow-up revisions

RevisionCommit summaryAuthorDate
r77290Follow-up to r76419 - override "ignore invisible divs" feature for now, since...yaron15:12, 25 November 2010

Status & tagging log