EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: rezzonico on February 25, 2014, 04:09:25 AM



Title: Form validation
Post by: rezzonico on February 25, 2014, 04:09:25 AM
Hi all,

I have a form similar to the following tutorial:
http://www.jeasyui.com/tutorial/form/form3.php

In my form I have two "easyui-datebox" fields: Start, End.
I want to add a validation that check that "Start" is less than "End".
I am able to do this at server site.
Is it possible to do this check during form validation ?

Regards.
Miche


Title: Re: Form validation
Post by: stworthy on February 26, 2014, 07:09:05 AM
A validate type must be extended to compare two date value. Please see the code below:
Code:
<script>
$.extend($.fn.validatebox.defaults.rules, {
greaterThan:{
validator: function(value,param){
var v1 = $(param[0]).datebox('getValue');
var d1 = $.fn.datebox.defaults.parser(v1);
var d2 = $.fn.datebox.defaults.parser(value);
return d2 > d1;
},
message: 'Please select a greater date.'
}
})
</script>

Once the 'greaterThan' validate type is ready, apply it to the second date box component.
Code:
<input id="d1" class="easyui-datebox" required>
<input id="d2" class="easyui-datebox" required validType="greaterThan['#d1']">


Title: Re: Form validation
Post by: rezzonico on February 27, 2014, 08:13:33 AM
Thanks stworthy !