Make the DropDwonList Selection Required
Environment
Product | Progress Kendo UI DropDownList for jQuery |
Operating System | Windows 10 64bit |
Visual Studio version | Visual Studio 2017 |
Preferred Language | JavaScript |
Description
How can I make the selection in a Kendo UI DropDownList required?
Solution
The DropDownList enables you to initialize it by using the input
or the select
element. If the selection from the DropDownList is mandatory, initialize it from an input
or select
element with a required
attribute. The following example uses the Kendo UI Validator to display the validation message.
<form id="myForm" action="someAction" method="post">
<input id="ddl" name="color" required/>
</form>
<button id="submitBtn" type="submit" class="k-button">Submit</button>
<script>
$("#ddl").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
dataSource: [
{ text: "Black", value: "1" },
{ text: "Orange", value: "2" },
{ text: "Grey", value: "3" }
],
optionLabel: "Select an option",
});
$("#submitBtn").click(function () {
var validator = $("#myForm").kendoValidator().data('kendoValidator');
validator.validate();
});
</script>
See Also
- JavaScript API Reference of the DropDownList
- How to Automatically Adjust the Width of a DropDownList
- How to Create DropDownLists with Long Items
- How to Detect Wrapper Focus Events
- How to Move the Group Label on Top of Items
- How to Prevent Popup Closure on Scroll
- How to Remove Items
- How to Set DataSource Dynamically
- How to Update MVVM Bound Models on Load