我有一个表格,需要显示“期望值”以反馈有关特定字段为何未通过验证的信息。
此期望值随不同的输入而变化,如下所示:
var varOne = $('#id_iNeedToCheck').val() ;
var varTwo = $('#id_iNeedToCheck2').val() ;
var expectedValue = ( varOne / 28) + (varTwo / 10) + 8 ;
$('#id_iNeedToCheck').change(function(){
return [varOne = $('#id_iNeedToCheck').val(),expectedValue = (varOne / 28) + (varTwo / 10) + 8] ;
});
自定义验证如下:
window.Parsley.addValidator('myValidator', {
validateNumber: function(value) {
if (value > expectedValue) {
return value - expectedValue <= 7 ;
}
else {
return expectedValue - value <= 7;
}
},
requirementType: 'string',
messages: {
en: 'Your input differs too much from what we expect, we expect ' + expectedValue + ', and your input can not be 7 more or 7 less than this value.'
}
});
内部
messages: {
en: 'Your input differs too much from what we expect, we expect ' + expectedValue + ', and your input can not be 7 more or 7 less than this value.'
}
此值永远不会更新,因为似乎此值仅解析一次,而自定义验证器则不断地解析并“按预期”工作。
随着“ expectedValue”不断变化,我如何确保此消息得到更新/解析?