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

Grid Field - If this then that

1 Answer 24 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 08 Jul 2013, 01:06 PM
The Model has 4 properties, Description, Amount, Note and a boolean, NoteRequired.
I have a grid with 3 columns, Description, Amount and Note.  
If NoteRequired is True for a row and the Amount > 0, how do I show them a message that a Note is Required and set the focus in the Note field?

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 08 Jul 2013, 02:51 PM
Hi James,

You can use custom validation. The code below uses the Grid's Inline Editing demo as a starting point.

In case you are using the Grid's MVC wrapper, you can refer to the "Custom validator editing" example, which is included in the offline demos.

The code below also demonstrates how to retrieve the other edit values, not just the one that currently fires validation.


fields: {
    ProductID: { editable: false, nullable: true },
    ProductName: { validation: { required: true } },
    UnitPrice: { type: "number", validation: {
        custom: function (input) {
            var row = input.closest(".k-grid-edit-row"),
                rowModel = $("#grid").data("kendoGrid").dataItem(row);
                 
            if (input.val() < 5) { // validation fails
                input.attr("data-custom-msg", "Custom invalid message");
                return false;
            }
            return true;
        }                                           
    } },
    Discontinued: { type: "boolean" },
    UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}


Regards,
Dimo
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
James
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or