|
| 1 | +/** |
| 2 | + * Deprecated functions and attributes |
| 3 | + * @todo: Remove in release of 3.0 |
| 4 | + */ |
| 5 | +(function ($, undefined) { |
| 6 | + |
| 7 | + 'use strict'; |
| 8 | + |
| 9 | + /** |
| 10 | + * @deprecated |
| 11 | + * @param language |
| 12 | + * @param conf |
| 13 | + */ |
| 14 | + $.fn.validateForm = function (language, conf) { |
| 15 | + $.formUtils.warn('Use of deprecated function $.validateForm, use $.isValid instead'); |
| 16 | + return this.isValid(language, conf, true); |
| 17 | + }; |
| 18 | + |
| 19 | + $.formUtils.$win.bind('validatorsLoaded formValidationSetup', function(evt, $form, config) { |
| 20 | + if( !$form ) { |
| 21 | + $form = $('form'); |
| 22 | + } |
| 23 | + |
| 24 | + addSupportForCustomErrorMessageCallback(config); |
| 25 | + addSupportForElementReferenceInPositionParam(config); |
| 26 | + addSupportForValidationDependingOnCheckedInput($form); |
| 27 | + }); |
| 28 | + |
| 29 | + |
| 30 | + function addSupportForCustomErrorMessageCallback(config) { |
| 31 | + if (config && |
| 32 | + config.errorMessagePosition === 'custom' && |
| 33 | + typeof config.errorMessageCustom === 'function') { |
| 34 | + |
| 35 | + $.formUtils.warn('Use of deprecated function errorMessageCustom, use config.submitErrorMessageCallback instead'); |
| 36 | + |
| 37 | + config.submitErrorMessageCallback = function($form, errorMessages) { |
| 38 | + config.errorMessageCustom( |
| 39 | + $form, |
| 40 | + config.language.errorTitle, |
| 41 | + errorMessages, |
| 42 | + config |
| 43 | + ); |
| 44 | + }; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + function addSupportForElementReferenceInPositionParam(config) { |
| 49 | + if (config.errorMessagePosition && typeof config.errorMessagePosition === 'object') { |
| 50 | + $.formUtils.warn('Deprecated use of config parameter errorMessagePosition, use config.submitErrorMessageCallback instead'); |
| 51 | + var $errorMessageContainer = config.errorMessagePosition; |
| 52 | + config.errorMessagePosition = 'top'; |
| 53 | + config.submitErrorMessageCallback = function() { |
| 54 | + return $errorMessageContainer; |
| 55 | + }; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + function addSupportForValidationDependingOnCheckedInput($form) { |
| 60 | + var $inputsDependingOnCheckedInputs = $form.find('[data-validation-if-checked]'); |
| 61 | + if ($inputsDependingOnCheckedInputs.length) { |
| 62 | + $.formUtils.warn( |
| 63 | + 'Detected use of attribute "data-validation-if-checked" which is '+ |
| 64 | + 'deprecated. Use "data-validation-depends-on" provided by module "logic"' |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + $inputsDependingOnCheckedInputs |
| 69 | + .on('beforeValidation', function() { |
| 70 | + |
| 71 | + var $elem = $(this), |
| 72 | + nameOfDependingInput = $elem.valAttr('if-checked'); |
| 73 | + |
| 74 | + // Set the boolean telling us that the validation depends |
| 75 | + // on another input being checked |
| 76 | + var $dependingInput = $('input[name="' + nameOfDependingInput + '"]', $form), |
| 77 | + dependingInputIsChecked = $dependingInput.is(':checked'), |
| 78 | + valueOfDependingInput = ($.formUtils.getValue($dependingInput) || '').toString(), |
| 79 | + requiredValueOfDependingInput = $elem.valAttr('if-checked-value'); |
| 80 | + |
| 81 | + if (!dependingInputIsChecked || !( |
| 82 | + !requiredValueOfDependingInput || |
| 83 | + requiredValueOfDependingInput === valueOfDependingInput |
| 84 | + )) { |
| 85 | + $elem.valAttr('skipped', true); |
| 86 | + } |
| 87 | + |
| 88 | + }); |
| 89 | + } |
| 90 | + |
| 91 | +})(jQuery); |
0 commit comments