I have these two Input boxes
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')
);
and i am using this jquery validate:
$('#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'); ?>"
}
});
I used the greaterThan as I have seen in this url but that is for dates only I think because my code above does not work. What is the equivalent of the greaterThan for numbers? Or are there any?
EDIT:
adding this worked out, new question: How do I Validate again when I corrected the end_inv without going back to the beg_inv to trigger the rule. If I add a new rule it will create a new error line instead of overwriting the first error message. Fiddle here by Riley
$.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}.');