[英]Critical dependency: the request of a dependency is an expression on jQuery Form Validator plugin
I have problem on loading security module from jQuery Form Validator plugin : 我在从jQuery Form Validator插件加载安全模块时遇到问题:
$.validate({
modules : 'security'
});
I'm using webpack and Laravel-mix for boundeling my files and I got this error: 我正在使用webpack和Laravel-mix来限制文件的大小,但出现此错误:
Critical dependency: the request of a dependency is an expression. 关键依赖项:依赖项的请求是一个表达式。
Every thing is fine and even the validations is working but this warning might break some other files to be bundled. 一切都很好,甚至验证都可以,但是此警告可能会破坏其他要捆绑的文件。
I found that this is problem with loadModules
function . 我发现这是
loadModules
函数的问题。
Here is how you can fix it: Instead of loading the whole security.js
or other modules you should grape your validation from that module instead of loading it all and then add it to your main js file. 解决方法如下:与其加载整个
security.js
或其他模块,不如从该模块获取验证,而不是全部加载,然后将其添加到主js文件中。 Here I need confirmation from security.js: 在这里,我需要来自security.js的确认:
import './form-validation';
$.formUtils.addValidator({
name: 'confirmation',
validatorFunction: function (value, $el, config, language, $form) {
var password,
passwordInputName = $el.valAttr('confirm') ||
($el.attr('name') + '_confirmation'),
$passwordInput = $form.find('[name="' + passwordInputName + '"]');
if (!$passwordInput.length) {
$.formUtils.warn('Password confirmation validator: could not find an input ' +
'with name "' + passwordInputName + '"', true);
return false;
}
password = $passwordInput.val();
if (config.validateOnBlur && !$passwordInput[0].hasValidationCallback) {
$passwordInput[0].hasValidationCallback = true;
var keyUpCallback = function () {
$el.validate();
};
$passwordInput.on('keyup', keyUpCallback);
$form.one('formValidationSetup', function () {
$passwordInput[0].hasValidationCallback = false;
$passwordInput.off('keyup', keyUpCallback);
});
}
return value === password;
},
errorMessage: '',
errorMessageKey: 'notConfirmed'
});
$.validate({
form: '#signup-header',
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.