|
334 | 334 | 'node': node, |
335 | 335 | 'function': 'delegateDynamicValidation()', |
336 | 336 | 'arguments': JSON.stringify(options), |
337 | | - 'message': 'OK - Dynamic Validation activated on ' + $(node).length + ' form(s)' |
| 337 | + 'message': 'OK - Dynamic Validation activated on ' + node.length + ' form(s)' |
338 | 338 | }); |
339 | 339 | // {/debug} |
340 | 340 |
|
341 | | - if ( !$(node).find('[' + _data.validation + '],[' + _data.regex + ']')[0]) { |
| 341 | + if ( !node.find('[' + _data.validation + '],[' + _data.regex + ']')[0]) { |
342 | 342 |
|
343 | 343 | // {debug} |
344 | 344 | options.debug && window.Debug.log({ |
345 | 345 | 'node': node, |
346 | 346 | 'function': 'delegateDynamicValidation()', |
347 | | - 'arguments': '$(node).find([' + _data.validation + '],[' + _data.regex + '])', |
| 347 | + 'arguments': 'node.find([' + _data.validation + '],[' + _data.regex + '])', |
348 | 348 | 'message': 'ERROR - [' + _data.validation + '] not found' |
349 | 349 | }); |
350 | 350 | // {/debug} |
|
359 | 359 | } |
360 | 360 |
|
361 | 361 | $.each( |
362 | | - $(node).find('[' + _data.validation + '],[' + _data.regex + ']'), |
| 362 | + node.find('[' + _data.validation + '],[' + _data.regex + ']'), |
363 | 363 | function (index, input) { |
364 | 364 |
|
365 | 365 | $(input).unbind(event).on(event, function (e) { |
|
395 | 395 | ) |
396 | 396 | } |
397 | 397 |
|
398 | | - var _typeWatch = (function(){ |
399 | | - var timer = 0; |
400 | | - return function(callback, ms){ |
401 | | - clearTimeout (timer); |
402 | | - timer = setTimeout(callback, ms); |
403 | | - } |
404 | | - })(); |
405 | | - |
406 | 398 | /** |
407 | 399 | * Delegates the submit validation on data-validation and data-validation-regex attributes based on trigger. |
408 | 400 | * Note: Disable the form submit function so the callbacks are not by-passed |
|
418 | 410 | 'node': node, |
419 | 411 | 'function': 'delegateValidation()', |
420 | 412 | 'arguments': JSON.stringify(options), |
421 | | - 'message': 'OK - Validation activated on ' + $(node).length + ' form(s)' |
| 413 | + 'message': 'OK - Validation activated on ' + node.length + ' form(s)' |
422 | 414 | }); |
423 | 415 | // {/debug} |
424 | 416 |
|
425 | | - if (!$(node).find(options.submit.settings.button)[0]) { |
| 417 | + if (!node.find(options.submit.settings.button)[0]) { |
426 | 418 |
|
427 | 419 | // {debug} |
428 | 420 | options.debug && window.Debug.log({ |
429 | 421 | 'node': node, |
430 | 422 | 'function': 'delegateDynamicValidation()', |
431 | | - 'arguments': '$(node).find(' + options.submit.settings.button + ')', |
| 423 | + 'arguments': 'node.find(' + options.submit.settings.button + ')', |
432 | 424 | 'message': 'ERROR - ' + options.submit.settings.button + ' not found' |
433 | 425 | }); |
434 | 426 | // {/debug} |
|
437 | 429 |
|
438 | 430 | } |
439 | 431 |
|
440 | | - $(node).on("submit", false ); |
441 | | - $(node).find(options.submit.settings.button).unbind(event).on(event, function (e) { |
| 432 | + node.on("submit", false); |
| 433 | + node.find(options.submit.settings.button).unbind(event).on(event, function (e) { |
442 | 434 |
|
443 | 435 | e.preventDefault(); |
444 | 436 |
|
|
484 | 476 | var isValid = true; |
485 | 477 |
|
486 | 478 | $.each( |
487 | | - $(node).find('[' + _data.validation + '],[' + _data.regex + ']'), |
| 479 | + node.find('[' + _data.validation + '],[' + _data.regex + ']'), |
488 | 480 | function (index, input) { |
489 | 481 |
|
490 | 482 | if ($(this).is(':disabled')) { |
|
733 | 725 | // Compare Field values |
734 | 726 | if (isNaN(compared)) { |
735 | 727 |
|
736 | | - comparedValue = $(node).find('[name="' + compared + '"]').val(); |
| 728 | + comparedValue = node.find('[name="' + compared + '"]').val(); |
737 | 729 | if (!comparedValue) { |
738 | 730 |
|
739 | 731 | // {debug} |
|
817 | 809 | return false; |
818 | 810 | } |
819 | 811 |
|
820 | | - input = $(node).find('[name="' + inputName + '"]'); |
| 812 | + input = node.find('[name="' + inputName + '"]'); |
821 | 813 |
|
822 | 814 | label = null; |
823 | 815 |
|
|
839 | 831 |
|
840 | 832 | if (group) { |
841 | 833 |
|
842 | | - groupInput = $(node).find('[name="' + inputName + '"]'); |
843 | | - label = $(node).find('[id="' + group + '"]'); |
| 834 | + groupInput = node.find('[name="' + inputName + '"]'); |
| 835 | + label = node.find('[id="' + group + '"]'); |
844 | 836 |
|
845 | 837 | if (label[0]) { |
846 | 838 | label.addClass(options.submit.settings.errorClass); |
847 | 839 | errorContainer = label; |
848 | 840 | } |
849 | 841 |
|
850 | | - //$(node).find('[' + _data.group + '="' + group + '"]').addClass(options.submit.settings.errorClass) |
| 842 | + //node.find('[' + _data.group + '="' + group + '"]').addClass(options.submit.settings.errorClass) |
851 | 843 |
|
852 | 844 | } else { |
853 | 845 |
|
|
860 | 852 | inputId = input.attr('id'); |
861 | 853 |
|
862 | 854 | if (inputId) { |
863 | | - label = $(node).find('label[for="' + inputId + '"]')[0]; |
| 855 | + label = node.find('label[for="' + inputId + '"]')[0]; |
864 | 856 | } |
865 | 857 |
|
866 | 858 | if (!label) { |
|
876 | 868 | if (options.submit.settings.display === 'inline') { |
877 | 869 | errorContainer = errorContainer || input.parent(); |
878 | 870 | } else if (options.submit.settings.display === 'block') { |
879 | | - errorContainer = $(node); |
| 871 | + errorContainer = node; |
880 | 872 | } |
881 | 873 |
|
882 | 874 | // Prevent double error list if the previous one has not been cleared. |
|
990 | 982 | } else { |
991 | 983 |
|
992 | 984 | if (!input) { |
993 | | - input = $(node).find('[name="' + inputName + '"]'); |
| 985 | + input = node.find('[name="' + inputName + '"]'); |
994 | 986 |
|
995 | 987 | if (!input[0]) { |
996 | 988 |
|
|
1022 | 1014 | errors = []; |
1023 | 1015 | window.Validation.hasScrolled = false; |
1024 | 1016 |
|
1025 | | - $(node).find('[' + _data.errorList + ']').remove(); |
1026 | | - $(node).find('.' + options.submit.settings.errorClass).removeClass(options.submit.settings.errorClass); |
| 1017 | + node.find('[' + _data.errorList + ']').remove(); |
| 1018 | + node.find('.' + options.submit.settings.errorClass).removeClass(options.submit.settings.errorClass); |
1027 | 1019 |
|
1028 | 1020 | } |
1029 | 1021 |
|
1030 | 1022 | /** |
1031 | 1023 | * Submits the form once it succeeded the validation process. |
1032 | | - * Note: This function will be overridden if "options.submit.settings.onSubmit" is defined |
| 1024 | + * Note: |
| 1025 | + * - This function will be overridden if "options.submit.settings.onSubmit" is defined |
| 1026 | + * - The node can't be submitted by jQuery since it has been disabled, use the form native submit function instead |
1033 | 1027 | */ |
1034 | 1028 | function submitForm () { |
1035 | 1029 |
|
1036 | | - node.submit(); |
| 1030 | + node[0].submit() |
1037 | 1031 |
|
1038 | 1032 | } |
1039 | 1033 |
|
|
1055 | 1049 | value = ($(input).is(':checked')) ? 1 : ''; |
1056 | 1050 | break; |
1057 | 1051 | case 'radio': |
1058 | | - value = $(node).find('input[name="' + $(input).attr('name') + '"]:checked').val() || ''; |
| 1052 | + value = node.find('input[name="' + $(input).attr('name') + '"]:checked').val() || ''; |
1059 | 1053 | break; |
1060 | 1054 | default: |
1061 | 1055 | value = $(input).val(); |
|
1066 | 1060 |
|
1067 | 1061 | }; |
1068 | 1062 |
|
| 1063 | + /** |
| 1064 | + * @private |
| 1065 | + * Execute function once the timer is reached. |
| 1066 | + * If the function is recalled before the timer ends, the first call will be canceled. |
| 1067 | + */ |
| 1068 | + var _typeWatch = (function(){ |
| 1069 | + var timer = 0; |
| 1070 | + return function(callback, ms){ |
| 1071 | + clearTimeout (timer); |
| 1072 | + timer = setTimeout(callback, ms); |
| 1073 | + } |
| 1074 | + })(); |
| 1075 | + |
1069 | 1076 | /** |
1070 | 1077 | * @private |
1071 | 1078 | * Executes an anonymous function or a string reached from the window scope. |
|
1423 | 1430 | } |
1424 | 1431 |
|
1425 | 1432 | return node.each(function () { |
1426 | | - |
1427 | | - window.Validation.form[node.selector] = new Validation(this, options); |
1428 | | - |
| 1433 | + window.Validation.form[node.selector] = new Validation($(this), options); |
1429 | 1434 | }); |
1430 | 1435 |
|
1431 | 1436 | }, |
|
0 commit comments