我有这两个输入框
form_open('performances/save/'.$performance_info->prf_id,array('id'=>'performance_form'));
form_input(array(
'class'=>'beg_inv',
'name'=>'beg_inv',
'id'=>'beg_inv',
'value'=>$performance_info->beg_inv);
form_input(array(
'class'=>'end_inv',
'name'=>'end_inv',
'id'=>'end_inv',
'value'=>$performance_info->end_inv);
form_submit(array(
'name'=>'submit',
'id'=>'submit',
'value'=>$this->lang->line('common_submit'),
'class'=>'submit_button float_right')
);
我正在使用这个jquery验证:
$('#performance_form').validate({
submitHandler:function(form)
{
$('#prf_id').val($('#scan_performance').val());
$(form).ajaxSubmit({
success:function(response)
{
tb_remove();
post_exp_form_submit(response);
},
dataType:'json'
});
},
errorLabelContainer: "#error_message_box",
wrapper: "li",
rules:
{
prod_id:"required",
beg_inv: { greaterThan: "#end_inv" }
},
messages:
{
prod_id:"<?php echo $this->lang->line('performances_product'); ?>",
beg_inv:"<?php echo $this->lang->line('performances_qty_val'); ?>"
}
});
我使用了bigThan,正如我在url中所看到的那样,但我认为这只是日期,因为上面的代码不起作用。数字的bigThan相当于什么?或者有没有?
编辑:
添加这个问题,新问题:当我更正end_inv而不返回到beg_inv以触发规则时,如何再次验证。如果我添加新规则,它将创建一个新的错误行,而不是覆盖第一个错误消息。莱利小提琴here
$.validator.addMethod(
"greaterThan",
function (value, element, params)
{
var target = $(params).val();
var isValueNumeric = !isNaN(parseFloat(value)) && isFinite(value);
var isTargetNumeric = !isNaN(parseFloat(target)) && isFinite(target);
if (isValueNumeric && isTargetNumeric) {
return Number(value) > Number(target);
}
if (!/Invalid|NaN/.test(new Date(value))) {
return new Date(value) > new Date(target);
}
return false;
}, 'Must be greater than {0}.');