如何覆盖默认验证器的默认消息?
How to overwrite a default message for a default validator?
我工作的遗留应用程序之一是使用内联表单验证引擎 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">
None 其中对我有用,而不是显示自定义消息,而是显示默认消息:
有人知道如何实现吗?这让我发疯!
基于数据属性的新型配置取代了基于 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>
我工作的遗留应用程序之一是使用内联表单验证引擎 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">
None 其中对我有用,而不是显示自定义消息,而是显示默认消息:
有人知道如何实现吗?这让我发疯!
基于数据属性的新型配置取代了基于 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>