grid popup template with custom validation
by bryan3d4
HTML
<script src="http://demos.kendoui.com/content/shared/js/people.js"></script>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.2.913/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.2.913/styles/kendo.common.min.css">
<script src="http://cdn.kendostatic.com/2012.2.913/js/kendo.all.min.js"></script>
<!-- grid element -->
<div id="grid" style="width: 700px; margin: 0 auto;"></div>
<!-- popup editor template -->
<script id="popup_editor" type="text/x-kendo-template">
<p>Custom editor template</p>
<div class="k-edit-label">
<label for="FirstName">First Name</label>
</div>
<!-- autoComplete editor for field: "FirstName" -->
<input name="FirstName"
data-bind="value:FirstName"
data-value-field="firstName"
data-text-field="firstName"
data-source="autoCompleteDS"
data-role="autocomplete" />
<div class="k-edit-label">
<label for="LastName" style="color: red;">Last Name</label>
</div>
<!-- textbox editor for field: "LastName" -->
<!-- field: "LastName" is not included as a grid column -->
<input type="text" class="k-input k-textbox" name="LastName" data-bind="value:LastName">
<div class="k-edit-label">
<label for="BirthDate">Birth Date</label>
</div>
<!-- datepicker editor for field: "BirthDate" -->
<input type="text"
name="BirthDate"
data-type="date"
data-bind="value:BirthDate"
data-role="datepicker" />
<div class="k-edit-label">
<label for="Age">Age</label>
</div>
<!-- numeric textbox editor for field: "Age" -->
<input type="text" name="Age" data-type="number" data-bind="value:Age" data-role="numerictextbox" />
</script>
JavaScript
var data = createRandomData(50);
var autoCompleteDS = new kendo.data.DataSource({
data: [
{
firstName: "Alex"},
{
firstName: "Alice"},
{
firstName: "Antony"},
{
firstName: "Anne"},
{
firstName: "Anna"}
]
});
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
data: data,
schema: {
model: {
fields: {
FirstName: {
type: "string"
},
LastName: {
type: "string"
},
City: {
type: "string"
},
Title: {
type: "string"
},
BirthDate: {
type: "date"
},
Age: {
type: "number",
validation: {
required:true,
ageCheck: function(input){
if (input.attr("name") == "Age"){
input.attr("data-ageCheck-msg", "Age must be greater than 10");
return input.val() > 10;
}
return true;
}
}
}
}
}
},
pageSize: 10
},
height: 450,
scrollable: true,
sortable: true,
pageable: true,
editable: {
mode: "popup",
template: kendo.template($("#popup_editor").html())
},
edit: function(e) {
},
toolbar: ["create"],
...