Index: trunk/extensions/SemanticForms/libs/SemanticForms.js |
— | — | @@ -250,6 +250,7 @@ |
251 | 251 | // checked - otherwise, hide it |
252 | 252 | function showIfChecked(checkbox_inputs, div_id) { |
253 | 253 | the_div = document.getElementById(div_id); |
| 254 | + if ( the_div == null ) { return; } |
254 | 255 | for (var i in checkbox_inputs) { |
255 | 256 | checkbox = document.getElementById(checkbox_inputs[i]); |
256 | 257 | if (checkbox != null && checkbox.checked) { |
— | — | @@ -266,11 +267,15 @@ |
267 | 268 | eval(sfgShowOnSelectCalls[i]); |
268 | 269 | } |
269 | 270 | |
| 271 | +function existsAndVisible(field) { |
| 272 | + return (field && field.offsetWidth); |
| 273 | +} |
| 274 | + |
270 | 275 | function validate_mandatory_field(field_id, info_id) { |
271 | 276 | var field = document.getElementById(field_id); |
272 | 277 | // if there's nothing at that field ID, ignore it - it's probably |
273 | 278 | // a hidden field |
274 | | - if (field == null) { |
| 279 | + if (!existsAndVisible(field)) { |
275 | 280 | return true; |
276 | 281 | } |
277 | 282 | if (field.value.replace(/\s+/, '') == '') { |
— | — | @@ -303,7 +308,7 @@ |
304 | 309 | var field = jQuery('input#' + field_id); |
305 | 310 | // if there's nothing at that field ID, ignore it - it's probably |
306 | 311 | // a hidden field |
307 | | - if (field == null) { |
| 312 | + if (!existsAndVisible(field)) { |
308 | 313 | return true; |
309 | 314 | } |
310 | 315 | // FIXME |
— | — | @@ -459,6 +464,18 @@ |
460 | 465 | } |
461 | 466 | scroll(0, 0); |
462 | 467 | } |
| 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 | + } |
463 | 480 | return (num_errors == 0); |
464 | 481 | } |
465 | 482 | |