EasyUI Forum
May 08, 2024, 03:34:22 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Form validation  (Read 12538 times)
rezzonico
Full Member
***
Posts: 183


View Profile
« 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
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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']">
Logged
rezzonico
Full Member
***
Posts: 183


View Profile
« Reply #2 on: February 27, 2014, 08:13:33 AM »

Thanks stworthy !
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!