EasyUI Forum
November 01, 2025, 05:47:54 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: Editable Datagrid with Validators  (Read 9373 times)
Andy1980
Newbie
*
Posts: 14


View Profile Email
« on: March 04, 2014, 04:00:01 AM »

Hi Experts,

how would you manage it, to get a editable datagrid with fields "from" and "to", which both should a validator like "from" must be less equal to field "to"

I did the following:


Code:
$.extend($.fn.validatebox.defaults.rules, {
$.extend($.fn.validatebox.defaults.rules, {
   from: {
        validator: function(value, param){
            var ed1 = $('#Tolerances_grid').datagrid('getEditor', {index:my_single_update_index,field:'TO'});
            var to_value = $(ed1.target).val()
            return to_value >= value;
        },
        message: 'From must be lesser than or equals To.'
    },
   to: {
        validator: function(value, param){
            var ed2 = $('#Tolerances_grid').datagrid('getEditor', {index:my_single_update_index,field:'FROM'});
            var from_value = $(ed2.target).val()
            return from_value <= value;
        },
        message: 'To must be greater than or equals From.'
    }
});   

And here is the field defintion:

Code:
          {field:'FROM',title:'From',width:70, editor:{
                                               type:"validatebox",
                                               options:{
                                                 validType:"from[]"
                                              }
                                           }},
          {field:'TO',title:'To',width:70, editor:{
                                              type:"validatebox",
                                              options:{
                                                 validType:"to[]"
                                              }
                                           }},

The code is working fine, but I think it can be much easier, with a row validator perhaps?
If yes, can u give me simple example ?

And i don't like this lines here:
Code:
var ed2 = $('#Tolerances_grid').datagrid('getEditor', {index:my_single_update_index,field:'FROM'});
var from_value = $(ed2.target).val()

I wonder, why i can't use the action getValue() from the editor to get value?

Any ideas?

Thanks.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: March 04, 2014, 07:05:58 AM »

Another solution is to extend the validators as below:
Code:
$.extend($.fn.validatebox.defaults.rules, {
from: {
validator: function(value, param){
return value < $(param[0]).val();
},
message: 'The value is too big.'
},
to: {
validator: function(value, param){
return value >= $(param[0]).val()
},
message: 'The value is too small.'
}
})

When editing a row, apply these validator to corresponding editors.
Code:
var dg = $('#dg');
dg.datagrid('beginEdit', index);
var ed1 = dg.datagrid('getEditor', {index:index,field:'FROM'});
var ed2 = dg.datagrid('getEditor', {index:index,field:'TO'});

$(ed1.target).attr('id','_from').validatebox({
required:true,
validType:'from["#_to"]'
});
$(ed2.target).attr('id','_to').validatebox({
required:true,
validType:'to["#_from"]'
});
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!