Grid Field - If this then that

2 posts, 1 answers
  1. James
    James avatar
    5 posts
    Member since:
    Apr 2011

    Posted 08 Jul 2013 Link to this post

    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?

  2. Answer
    Dimo
    Admin
    Dimo avatar
    8445 posts

    Posted 08 Jul 2013 Link to this post

    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!
Back to Top