This is a migrated thread and some comments may be shown as answers.

custom Validator in grid

4 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vijay
Top achievements
Rank 1
Vijay asked on 23 Apr 2014, 02:35 PM
Hi,
   I have a grid which is editable. On focus on the cell of the grid if the cell is editable it will show a textbox or a combobox . This works fine. I have put required field validator on the combobbox and that also works fine. That is if I press tab key on an empty combobox in the grid the message is displayed and the focus is set to the combobox itself. Now coming to my problem. If the combobox has invalid data I need to validate it using the kendo validator and custom validation. But I am unable to set the focus on to the combobox and hence the focus goes to the next cell and the message is also not displayed. Please help.
Thanks in advance.
Regards,
Vijay

4 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Popov
Telerik team
answered on 25 Apr 2014, 02:02 PM
Hi Vijay,

This could be achieved by extending the built-in Validator with your custom rule. For example: 
<script type="text/javascript">
    (function ($, kendo) {
        //Extending the Grid build in validator
        $.extend(true, kendo.ui.validator, {
            messages: {
                myRule: "error"
            },
            rules: {
                myRule: function (input) {
                    if (input.is("[name=ComboBoxFieldNameGoesHere]")) {
                        return false
                    }
                    return true;
                }
            }
        });
    })(jQuery, kendo);
</script>


Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Kryszal
Top achievements
Rank 1
answered on 20 Aug 2015, 10:17 AM
So, if the built-in Validator will be extended, how it is possible to execute some methods on this validator (e.g. inside custom rules) ? How to get the validator object to call for example 'validator.validateInput(input)'?
0
Kryszal
Top achievements
Rank 1
answered on 20 Aug 2015, 11:38 AM

I found something like this:

$("#grid").kendoValidator().data("kendoValidator");

Is it correct?

0
Alexander Popov
Telerik team
answered on 24 Aug 2015, 08:13 AM
Hi Kryszal,

This Validator is initialized each time the Grid enters edit mode, so you would have to use the Grid's edit event handler to get its instance. For example: 
function onEdit(e){
  var validator = e.container.getKendoValidator();
  ...
}

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Vijay
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Kryszal
Top achievements
Rank 1
Share this question
or