我工作的传统应用程序之一是使用Inline Form Validation Engine 2.6.2,又名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">
他们都不为我工作,而是显示默认消息,而不是显示自定义消息:
有人知道如何实现这一目标吗?这让我发疯了!
答案 0 :(得分:1)
基于数据属性的较新类型的配置替换了基于class
属性的配置,因此您必须一直使用并为此使用data-validation-engine
属性:
$("form").validationEngine();
body { margin: 20px }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery-Validation-Engine/2.6.2/languages/jquery.validationEngine-en.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery-Validation-Engine/2.6.2/jquery.validationEngine.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jQuery-Validation-Engine/2.6.2/validationEngine.jquery.min.css">
<form>
Confirm you have read and agree:<br>
<input type="checkbox" name="agreement" value="1"
data-validation-engine="validate[minCheckbox[1]]"
data-errormessage-range-underflow="Custom error msg">
I have read and agree<br>
<button>Submit</button>
</form>