Validation of two grid boolean columns where one has to be checked

3 posts, 0 answers
  1. Florian
    Florian avatar
    14 posts
    Member since:
    Nov 2015

    Posted 28 Apr 2016 Link to this post

    Hi

     

    I need a way to validate on my grid that at least one of two checkboxes is checked

     

    I think this is not possible with the validation-extension {$.extend(true, kendo.ui.validator ...} method?

     

    What would be the best way to achive this?

     

    My grid is set to inline-editing

    Is it possible to intercept, when the user clicks the save/update - button?

     

    kind regards

    Florian

  2. Florian
    Florian avatar
    14 posts
    Member since:
    Nov 2015

    Posted 29 Apr 2016 in reply to Florian Link to this post

    Hi

     

    I found a solution, if there is an more elegant way, you're welcome

     

    (($, kendo) =>
    {
        var notCheckedMenu1: Boolean = false;
     
        $.extend(true, kendo.ui.validator, {
            rules: {
                externalOrderValidation(input)
                {
                    if (input.is("[name='menu_1_flag']") && input.is("[type='checkbox']"))
                    {
                        if (input.prop("checked") === false)
                        {
                            notCheckedMenu1 = true;
                        } else
                        {
                            notCheckedMenu1 = false;
                        }
                    }
     
                    if (input.is("[name='menu_2_flag']") && input.is("[type='checkbox']") && input.prop("checked") === false)
                    {
                        if (notCheckedMenu1 === true)
                        {
                            input.attr("data-externalOrderValidation-msg", "Bitte ein Menü wählen!");
     
                            return false;
                        }
                    }
     
                    return true;
                }
            },
            messages: {
                externalOrderValidation(input)
                {
                    return input.attr("data-val-externalOrderValidation");
                }
            }
        });
    })(jQuery, kendo);

     

    Kind regards

    Florain

  3. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 02 May 2016 Link to this post

    Hi Florian,

    Another option for validating values from multiple columns would be to get reference to the dataItem, using the INPUT element and retrieve the value from the other columns:
    var dataItem = $("#grid").data("kendoGrid").dataItem(input.closest("TR"))

    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top