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

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

2 Answers 265 Views
Grid
This is a migrated thread and some comments may be shown as answers.
WenatexIT
Top achievements
Rank 1
WenatexIT asked on 28 Apr 2016, 07:13 AM

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 Answers, 1 is accepted

Sort by
0
WenatexIT
Top achievements
Rank 1
answered on 29 Apr 2016, 09:13 AM

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

0
Konstantin Dikov
Telerik team
answered on 02 May 2016, 05:47 AM
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!
 
Tags
Grid
Asked by
WenatexIT
Top achievements
Rank 1
Answers by
WenatexIT
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or