【发布时间】:2019-02-22 16:46:15
【问题描述】:
我工作的遗留应用程序之一是使用内联表单验证引擎 2.6.2 aka jQuery Validation Engine。我需要为默认验证器设置自定义消息。这是我尝试过但没有成功的所有方法,因为默认消息仍然显示,所以它不起作用。
这是 HTML:
<input type="checkbox" name="agreement" value="1" id="agreement_0" class="validate[minCheckbox[1]]">
<input type="checkbox" name="agreement" value="1" id="agreement_1" class="validate[minCheckbox[1]]">
还有 Javascript/jQuery:
// Use the data-errormessage-range-underflow attribute on the inputs
// Ex:
<input type="checkbox" name="agreement" value="1" id="agreement_0" class="validate[minCheckbox[1]]" data-errormessage-range-underflow="custom error msg">
// Use the default data-* attributes and the -range-underflow
// Ex:
<input type="checkbox"
name="agreement"
value="1"
id="agreement_0"
class="validate[minCheckbox[1]]"
data-errormessage-range-underflow="custom error msg"
data-errormessage-custom-error="custom error msg"
data-errormessage="custom error msg"
>
// Initialize the object with a custom message
// Ex:
<input type="checkbox"
name="agreement"
value="1"
id="agreement_0"
class="validate[minCheckbox[1]] someclass"
data-errormessage-range-underflow="custom error msg"
data-errormessage-custom-error="custom error msg"
data-errormessage="custom error msg"
>
$("#theform").validationEngine({'custom_error_messages' : {
'.someclass': {
'range-underflow': {
'message': "custom error message"
}
}
}
});
// Use the title attribute and add the custom message there
<input type="checkbox"
name="agreement"
value="1"
id="agreement_1"
class="validate[minCheckbox[1]]"
title="custom msg">
它们都不适合我,而不是显示自定义消息,而是显示默认消息:
有谁知道如何做到这一点?快把我逼疯了!
【问题讨论】:
-
我正在尝试查找 2.6.21 版本,但只能找到 2.6.4。能给个链接吗?
-
我在使用 jquery validate 时遇到了一个类似的问题(我不记得我使用的版本),并通过将“自定义消息”放在输入的属性“标题”中来解决它。希望这会有所帮助。
-
你指向的是2.6.2版本。但在你说的2.6.21问题中。是不是打错字了?
-
@trincot 不,这不是一个错字,tbh 我不知道他们在哪里或何时得到那个版本,但这是我们拥有的版本,我现在将尝试 H. Figuereido 解决方案,看看是否会它可以工作。
标签: javascript jquery jquery-validation-engine