chris
chris

Reputation: 4867

Kendo ui Multiselect validation

does anyone knows how to validate the Kendo UI Multiselect Widget with the Kendo UI validator?
I only want to check if the selections contains something or is empty.
The Multiselect should be required.

Thanks

Upvotes: 10

Views: 10526

Answers (1)

OnaBai
OnaBai

Reputation: 40887

Given a multiselect defined as:

<select id="tags" multiple="multiple" name="tags" required data-required-msg="Select start time"></select>

and the following JavaScript for initializing it:

var multi = $("#tags").kendoMultiSelect({
    dataSource: {
        transport: {
            read: function (op) {
                var data = [
                    "Option1", "Option2", "Option3", "Option4", "Option5"
                ];
                op.success(data);
            }
        }
    }
}).data("kendoMultiSelect");

Add the following code for validating it:

// Get reference to the validator
var validator = $("#tags").kendoValidator().data("kendoValidator");

// Bind validation to blur
$("input", multi.wrapper).on("blur", function() {
    validator.validate();
});

Upvotes: 15

Related Questions