|
42 | 42 | */ |
43 | 43 | attach: function(userOptions) { |
44 | 44 |
|
45 | | - if(!$(this).is("form")) { |
46 | | - console.log("Sorry, jqv.attach() only applies to a form"); |
47 | | - return this; |
48 | | - } |
49 | | - |
50 | 45 | var form = this; |
51 | 46 | var options; |
52 | 47 |
|
|
80 | 75 | * Unregisters any bindings that may point to jQuery.validaitonEngine |
81 | 76 | */ |
82 | 77 | detach: function() { |
83 | | - |
84 | | - if(!$(this).is("form")) { |
85 | | - alert("Sorry, jqv.detach() only applies to a form"); |
86 | | - return this; |
87 | | - } |
88 | 78 |
|
89 | 79 | var form = this; |
90 | 80 | var options = form.data('jqv'); |
|
117 | 107 | validate: function() { |
118 | 108 | var element = $(this); |
119 | 109 | var valid = null; |
120 | | - if(element.is("form") && !element.hasClass('validating')) { |
| 110 | + if((element.is("form") || element.hasClass(".validationEngineContainer")) && !element.hasClass('validating')) { |
121 | 111 | element.addClass('validating'); |
122 | 112 | var options = element.data('jqv'); |
123 | | - valid = methods._validateFields(this); |
| 113 | + var valid = methods._validateFields(this); |
124 | 114 |
|
125 | 115 | // If the form doesn't validate, clear the 'validating' class before the user has a chance to submit again |
126 | 116 | setTimeout(function(){ |
|
131 | 121 | } else if (!valid && options.onFailure) { |
132 | 122 | options.onFailure(); |
133 | 123 | } |
134 | | - } else if (element.is('form')) { |
| 124 | + } else if (element.is('form') || element.hasClass('.validationEngineContainer')) { |
135 | 125 | element.removeClass('validating'); |
136 | 126 | } else { |
137 | 127 | // field validation |
138 | | - var form = element.closest('form'); |
139 | | - var options = (form.data('jqv')) ? form.data('jqv') : $.validationEngine.defaults; |
140 | | - valid = methods._validateField(element, options); |
| 128 | + var form = element.closest('form, .validationEngineContainer'), |
| 129 | + options = (form.data('jqv')) ? form.data('jqv') : $.validationEngine.defaults, |
| 130 | + valid = methods._validateField(element, options); |
141 | 131 |
|
142 | 132 | if (valid && options.onFieldSuccess) |
143 | 133 | options.onFieldSuccess(); |
|
161 | 151 | var noAnimation = event.data.noAnimation; |
162 | 152 | } |
163 | 153 | else |
164 | | - var form = $(this.closest('form')); |
| 154 | + var form = $(this.closest('form, .validationEngineContainer')); |
165 | 155 |
|
166 | 156 | var options = form.data('jqv'); |
167 | 157 | // No option, take default one |
|
186 | 176 | * @param {String} possible values topLeft, topRight, bottomLeft, centerRight, bottomRight |
187 | 177 | */ |
188 | 178 | showPrompt: function(promptText, type, promptPosition, showArrow) { |
189 | | - var form = this.closest('form'); |
| 179 | + var form = this.closest('form, .validationEngineContainer'); |
190 | 180 | var options = form.data('jqv'); |
191 | 181 | // No option, take default one |
192 | 182 | if(!options) |
|
202 | 192 | * Closes form error prompts, CAN be invidual |
203 | 193 | */ |
204 | 194 | hide: function() { |
205 | | - var form = $(this).closest('form'); |
| 195 | + var form = $(this).closest('form, .validationEngineContainer'); |
206 | 196 | var options = form.data('jqv'); |
207 | 197 | var fadeDuration = (options && options.fadeDuration) ? options.fadeDuration : 0.3; |
208 | 198 | var closingtag; |
209 | 199 |
|
210 | | - if($(this).is("form")) { |
| 200 | + if($(this).is("form") || $(this).hasClass("validationEngineContainer")) { |
211 | 201 | closingtag = "parentForm"+methods._getClassName($(this).attr("id")); |
212 | 202 | } else { |
213 | 203 | closingtag = methods._getClassName($(this).attr("id")) +"formError"; |
|
238 | 228 | */ |
239 | 229 | _onFieldEvent: function(event) { |
240 | 230 | var field = $(this); |
241 | | - var form = field.closest('form'); |
| 231 | + var form = field.closest('form, .validationEngineContainer'); |
242 | 232 | var options = form.data('jqv'); |
243 | 233 | options.eventTrigger = "field"; |
244 | 234 | // validate the current field |
|
540 | 530 | limitErrors = true; |
541 | 531 | } |
542 | 532 |
|
543 | | - var form = $(field.closest("form")); |
| 533 | + var form = $(field.closest("form, .validationEngineContainer")); |
544 | 534 | // Fix for adding spaces in the rules |
545 | 535 | for (var i = 0; i < rules.length; i++) { |
546 | 536 | rules[i] = rules[i].replace(" ", ""); |
|
915 | 905 | break; |
916 | 906 | } |
917 | 907 | // old validation style |
918 | | - var form = field.closest("form"); |
| 908 | + var form = field.closest("form, .validationEngineContainer"); |
919 | 909 | var name = field.attr("name"); |
920 | 910 | if (form.find("input[name='" + name + "']:checked").size() == 0) { |
921 | 911 | if (form.find("input[name='" + name + "']:visible").size() == 1) |
|
940 | 930 | var classGroup = "["+options.validateAttribute+"*=" +rules[i + 1] +"]"; |
941 | 931 | var isValid = false; |
942 | 932 | // Check all fields from the group |
943 | | - field.closest("form").find(classGroup).each(function(){ |
| 933 | + field.closest("form, .validationEngineContainer").find(classGroup).each(function(){ |
944 | 934 | if(!methods._required($(this), rules, i, options)){ |
945 | 935 | isValid = true; |
946 | 936 | return false; |
|
1367 | 1357 | for (var i = 0; i < domIds.length; i++) { |
1368 | 1358 | var id = domIds[i]; |
1369 | 1359 | if ($(id).length) { |
1370 | | - var inputValue = field.closest("form").find(id).val(); |
| 1360 | + var inputValue = field.closest("form, .validationEngineContainer").find(id).val(); |
1371 | 1361 | var keyValue = id.replace('#', '') + '=' + escape(inputValue); |
1372 | 1362 | data[id.replace('#', '')] = inputValue; |
1373 | 1363 | } |
|
1529 | 1519 | var prompt = $('<div>'); |
1530 | 1520 | prompt.addClass(methods._getClassName(field.attr("id")) + "formError"); |
1531 | 1521 | // add a class name to identify the parent form of the prompt |
1532 | | - prompt.addClass("parentForm"+methods._getClassName(field.parents('form').attr("id"))); |
| 1522 | + prompt.addClass("parentForm"+methods._getClassName(field.closest('form, .validationEngineContainer').attr("id"))); |
1533 | 1523 | prompt.addClass("formError"); |
1534 | 1524 |
|
1535 | 1525 | switch (type) { |
|
1685 | 1675 | * @return undefined or the error prompt (jqObject) |
1686 | 1676 | */ |
1687 | 1677 | _getPrompt: function(field) { |
1688 | | - var formId = $(field).closest('form').attr('id'); |
| 1678 | + var formId = $(field).closest('form, .validationEngineContainer').attr('id'); |
1689 | 1679 | var className = methods._getClassName(field.attr("id")) + "formError"; |
1690 | 1680 | var match = $("." + methods._escapeExpression(className) + '.parentForm' + formId)[0]; |
1691 | 1681 | if (match) |
|
1906 | 1896 |
|
1907 | 1897 | _submitButtonClick: function(event) { |
1908 | 1898 | var button = $(this); |
1909 | | - var form = button.closest('form'); |
| 1899 | + var form = button.closest('form, .validationEngineContainer'); |
1910 | 1900 | form.data("jqv_submitButton", button.attr("id")); |
1911 | 1901 | } |
1912 | 1902 | }; |
|
0 commit comments