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

Adding a custom validator to a grid that is using GridEditMode.InCell

5 Answers 651 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 31 Jan 2017, 03:11 PM

Hello,

I'm trying to create a custom validator in a grid (which is using GridEditMode.InCell) but when the validation fail it shows the validation error just for a few milliseconds and then hide it. However when I left the field empty the default error "The xxxxx filed is required." is showed and do not disappear.

What should I do to achieve the same result with my custom validator?

The custom validator is the same I used in this question

http://www.telerik.com/forums/need-help-creating-two-kendo-validators-in-the-same-view#pzfZKgPe7UqXkPnRyN4grg

Thank you.

PS: I've attached a screenshot displaying the default required validator.

5 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 02 Feb 2017, 02:09 PM
Hello Andrew,

As you can see in the following online demo, the custom validation message is displayed correctly:
You can try to replicate the issue in a dojo example, so we can inspect it locally:

Best Regards,
Konstantin Dikov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Andrew
Top achievements
Rank 1
answered on 03 Feb 2017, 03:09 PM

Hello Konstantin,

I saw that demo before asking the question. In that demo what you're doing is extending the global validator and what I need is to create a local (custom) validator for the grid.

I need it in that way because I've a form and a grid in the same view and if I extend the global validator when I validate the form the rules defined in the global validator will be applied to the form validator as well.

Here's a snippet of what I'm doing

01.<div>
02.   <form id="form1">
03.   </form>
04.</div>
05. 
06.<div>
07.    @(Html.Kendo().Grid<ProductsModel>()
08.       .Name("grid")
09.       .....
10.    )
11.</div>
12. 
13.<script type="text/javascript">
14.    $("#form1").kendoValidator({
15.        rules: {
16.            custom: function (input) {
17.                console.log("Custom rules for the form");
18.                return true;
19.            }
20.        }
21.    })
22.</script>

 

As you can see in line 14 I'm creating a local validator for the form now what I need is to create another local validator for the grid would you please tell me how to create that validator? The grid is using .Editable(x => x.Mode(GridEditMode.InCell)).

Thank you.

0
Konstantin Dikov
Telerik team
answered on 07 Feb 2017, 11:58 AM
Hi Andrew,

You can initialize the validator over the wrapping element of the Grid, using its ID:
$("#grid").kendoValidator({...

Hope this helps.


Regards,
Konstantin Dikov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Andrew
Top achievements
Rank 1
answered on 09 Feb 2017, 05:43 PM

Hi Konstantin,

I tried what you suggested me

[quote]$("#grid").kendoValidator({...[/quote]

and the validator does the validation but when the validation fail the message isn't shown in the grid. The only message that is shown is "The field xxx is required" and this message is added automatically by the grid.

Any idea why is this happening?

Thank you.

0
Konstantin Dikov
Telerik team
answered on 13 Feb 2017, 09:18 AM
Hi Andrew,

After some further tests it seems that the approach with the initialization of the validator over a particular element will work with the other edit modes, but not with the InCell mode. With the InCell mode the error message is displayed correctly, but the cell is closing even if the validation fails (at least this is the behavior in my local tests).

With that limitation in mind I would recommend switching to the approach with the extending of the validator as shown in our online demo and check the field names before applied the validation (which will prevent the validation for the fields in the form):

Best Regards,
Konstantin Dikov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or