Index: trunk/extensions/SemanticForms/includes/SF_FormUtils.php |
— | — | @@ -28,10 +28,19 @@ |
29 | 29 | $javascript_text = <<<END |
30 | 30 | |
31 | 31 | function validate_mandatory_field(field_id, info_id) { |
32 | | - field = document.getElementById(field_id); |
| 32 | + var field = document.getElementById(field_id); |
| 33 | + // if there's nothing at that field ID, ignore it - it's probably |
| 34 | + // a hidden field |
| 35 | + if (field == null) { |
| 36 | + return true; |
| 37 | + } |
33 | 38 | if (field.value.replace(/\s+/, '') == '') { |
34 | | - infobox = document.getElementById(info_id); |
35 | | - infobox.innerHTML = "$blank_error_str"; |
| 39 | + var info_span = document.getElementById(info_id); |
| 40 | + if ( info_span == null ) { |
| 41 | + alert ("no info span found at " + info_id + "!"); |
| 42 | + } else { |
| 43 | + info_span.innerHTML = "$blank_error_str"; |
| 44 | + } |
36 | 45 | return false; |
37 | 46 | } else { |
38 | 47 | return true; |
— | — | @@ -43,27 +52,51 @@ |
44 | 53 | function validate_mandatory_radiobutton(none_button_id, info_id) { |
45 | 54 | none_button = document.getElementById(none_button_id); |
46 | 55 | if (none_button && none_button.checked) { |
47 | | - infobox = document.getElementById(info_id); |
48 | | - infobox.innerHTML = "$blank_error_str"; |
| 56 | + info_span = document.getElementById(info_id); |
| 57 | + info_span.innerHTML = "$blank_error_str"; |
49 | 58 | return false; |
50 | 59 | } else { |
51 | 60 | return true; |
52 | 61 | } |
53 | 62 | } |
54 | 63 | |
| 64 | +function validate_mandatory_combobox(field_id, info_id) { |
| 65 | + var field = jQuery('input#' + field_id); |
| 66 | + // if there's nothing at that field ID, ignore it - it's probably |
| 67 | + // a hidden field |
| 68 | + if (field == null) { |
| 69 | + return true; |
| 70 | + } |
| 71 | + // FIXME |
| 72 | + // field.val() unfortunately doesn't work in IE - it just returns |
| 73 | + // "undefined". For now, if that happens, just exit |
| 74 | + var value = field.val(); |
| 75 | + if (value == undefined) { |
| 76 | + alert(field.html()); |
| 77 | + return true; |
| 78 | + } |
| 79 | + if (value.replace(/\s+/, '') == '') { |
| 80 | + var info_span = document.getElementById(info_id); |
| 81 | + info_span.innerHTML = "$blank_error_str"; |
| 82 | + return false; |
| 83 | + } else { |
| 84 | + return true; |
| 85 | + } |
| 86 | +} |
| 87 | + |
55 | 88 | function validate_mandatory_checkboxes(field_id, info_id) { |
56 | | - elems = document.getElementsByTagName("*"); |
57 | | - var all_fields_unchecked = true; |
58 | | - for (var i = 0; i < elems.length; i++) { |
59 | | - if (elems[i].id == field_id) { |
60 | | - if (elems[i].checked) { |
61 | | - all_fields_unchecked = false; |
62 | | - } |
| 89 | + // get all checkboxes - the "field_id" in this case is the span |
| 90 | + // surrounding all the checkboxes |
| 91 | + var checkboxes = jQuery('span#' + field_id + " > span > input"); |
| 92 | + var all_unchecked = true; |
| 93 | + for (var i = 0; i < checkboxes.length; i++) { |
| 94 | + if (checkboxes[i].checked) { |
| 95 | + all_unchecked = false; |
63 | 96 | } |
64 | 97 | } |
65 | | - if (all_fields_unchecked) { |
66 | | - infobox = document.getElementById(info_id); |
67 | | - infobox.innerHTML = "$blank_error_str"; |
| 98 | + if (all_unchecked) { |
| 99 | + info_span = document.getElementById(info_id); |
| 100 | + info_span.innerHTML = "$blank_error_str"; |
68 | 101 | return false; |
69 | 102 | } else { |
70 | 103 | return true; |
— | — | @@ -102,26 +135,26 @@ |
103 | 136 | if (url_regexp.test(field.value)) { |
104 | 137 | return true; |
105 | 138 | } else { |
106 | | - infobox = document.getElementById(info_id); |
107 | | - infobox.innerHTML = "$bad_url_error_str"; |
| 139 | + info_span = document.getElementById(info_id); |
| 140 | + info_span.innerHTML = "$bad_url_error_str"; |
108 | 141 | return false; |
109 | 142 | } |
110 | 143 | } else if (type == 'email') { |
111 | 144 | // code borrowed from http://javascript.internet.com/forms/email-validation---basic.html |
112 | | - var email_regexp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/; |
| 145 | + var email_regexp = /^\s*\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+\s*$/; |
113 | 146 | if (email_regexp.test(field.value)) { |
114 | 147 | return true; |
115 | 148 | } else { |
116 | | - infobox = document.getElementById(info_id); |
117 | | - infobox.innerHTML = "$bad_email_error_str"; |
| 149 | + info_span = document.getElementById(info_id); |
| 150 | + info_span.innerHTML = "$bad_email_error_str"; |
118 | 151 | return false; |
119 | 152 | } |
120 | 153 | } else if (type == 'number') { |
121 | | - if (field.value.match(/^\-?[\d\.,]+$/)) { |
| 154 | + if (field.value.match(/^\s*\-?[\d\.,]+\s*$/)) { |
122 | 155 | return true; |
123 | 156 | } else { |
124 | | - infobox = document.getElementById(info_id); |
125 | | - infobox.innerHTML = "$bad_number_error_str"; |
| 157 | + info_span = document.getElementById(info_id); |
| 158 | + info_span.innerHTML = "$bad_number_error_str"; |
126 | 159 | return false; |
127 | 160 | } |
128 | 161 | } else if (type == 'date') { |
— | — | @@ -136,8 +169,8 @@ |
137 | 170 | // 'BC' and possibly other non-number strings |
138 | 171 | return true; |
139 | 172 | } else { |
140 | | - infobox = document.getElementById(info_id); |
141 | | - infobox.innerHTML = "$bad_date_error_str"; |
| 173 | + info_span = document.getElementById(info_id); |
| 174 | + info_span.innerHTML = "$bad_date_error_str"; |
142 | 175 | return false; |
143 | 176 | } |
144 | 177 | } else { |
— | — | @@ -278,7 +311,11 @@ |
279 | 312 | } |
280 | 313 | |
281 | 314 | static function autocompletionJavascript() { |
282 | | - global $wgScriptPath; |
| 315 | + global $wgScriptPath, $wgOut, $smwgScriptPath, $smwgJQueryIncluded; |
| 316 | + if ( !$smwgJQueryIncluded ) { |
| 317 | + $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-1.4.2.min.js" ); |
| 318 | + $smwgJQueryIncluded = true; |
| 319 | + } |
283 | 320 | |
284 | 321 | $javascript_text = <<<END |
285 | 322 | var autocompletemappings = new Array(); |
— | — | @@ -343,7 +380,7 @@ |
344 | 381 | } |
345 | 382 | } |
346 | 383 | |
347 | | -YAHOO.util.Event.addListener(window, 'load', attachAutocompleteToAllDocumentFields); |
| 384 | +jQuery.event.add(window, "load", attachAutocompleteToAllDocumentFields); |
348 | 385 | |
349 | 386 | END; |
350 | 387 | return $javascript_text; |
— | — | @@ -399,9 +436,9 @@ |
400 | 437 | return Xml::expandAttributes( $attribs ); |
401 | 438 | } else { |
402 | 439 | $out = ''; |
403 | | - foreach ( $attribs as $name => $val ) |
404 | | - $out .= " {$name}=\"" . Sanitizer::encodeAttribute( $val ) . '"'; |
405 | | - return $out; |
| 440 | + foreach ( $attribs as $name => $val ) |
| 441 | + $out .= " {$name}=\"" . Sanitizer::encodeAttribute( $val ) . '"'; |
| 442 | + return $out; |
406 | 443 | } |
407 | 444 | } |
408 | 445 | |
— | — | @@ -711,13 +748,13 @@ |
712 | 749 | '; |
713 | 750 | |
714 | 751 | $showRef = 'false'; |
715 | | - if ( (isset($wgHooks['ParserFirstCallInit']) && in_array('wfCite',$wgHooks['ParserFirstCallInit'])) || (isset($wgExtensionFunctions) && in_array('wfCite',$wgExtensionFunctions)) ) { |
| 752 | + if ( ( isset( $wgHooks['ParserFirstCallInit'] ) && in_array( 'wfCite', $wgHooks['ParserFirstCallInit'] ) ) || ( isset( $wgExtensionFunctions ) && in_array( 'wfCite', $wgExtensionFunctions ) ) ) { |
716 | 753 | $showRef = 'true'; |
717 | 754 | } |
718 | 755 | |
719 | 756 | $showSource = 'false'; |
720 | | - if ( (isset ($wgHooks['ParserFirstCallInit']) && in_array('efSyntaxHighlight_GeSHiSetup', $wgHooks['ParserFirstCallInit'])) |
721 | | - || (isset ($wgExtensionFunctions) && in_array('efSyntaxHighlight_GeSHiSetup', $wgExtensionFunctions)) ) { |
| 757 | + if ( ( isset( $wgHooks['ParserFirstCallInit'] ) && in_array( 'efSyntaxHighlight_GeSHiSetup', $wgHooks['ParserFirstCallInit'] ) ) |
| 758 | + || ( isset( $wgExtensionFunctions ) && in_array( 'efSyntaxHighlight_GeSHiSetup', $wgExtensionFunctions ) ) ) { |
722 | 759 | $showSource = 'true'; |
723 | 760 | } |
724 | 761 | |