I want to costomised validation, but right now it is showing incorrect validation , I am providing the screen sort and working code. pls provide the correct code so I can costomised the validation.
our working code is:
$("#EnterpriseNote-grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: {
url: "@Html.Raw(Url.Action("ListEnterpriseNoteData", "Enterprise", new { Id = ViewBag.EnterpriseID }))",
type: "POST",
dataType: "json",
// data: additionalData
}, create: {
url: "@Html.Raw(Url.Action("AddEntrpriseNoteData", "Enterprise", new { newdata = "", Id = ViewBag.EnterpriseID }))",
type: "GET",
dataType: "json",
// data: addAntiForgeryToken
},update: {
url: "@Html.Raw(Url.Action("EditEnterpriseNote", "Enterprise"))",
type: "POST",
dataType: "json",
// data: addAntiForgeryToken
},
destroy: {
url: "@Html.Raw(Url.Action("DeleteEnterpriseNote", "Enterprise"))",
type: "POST",
dataType: "json",
// data: addAntiForgeryToken
},
},
schema: {
data: "Data",
total: "Total",
errors: "Errors",
model: {
id: "Id",
fields: {
strNoteText: {
editable: true, type: "string",
validation: {
required: {
message: 'Note Text is required'
},
}
},
strNextReminderDate : { editable: true, type: "date" },
strFirstname: { editable: false, type: "string" },
strAssignedTo: {
editable: true, type: "string",
validation: {
required: {
message: 'PhoneNumber is required'
},
Assignedvalidation: function (input) {
var trimmedValue = input.val().trim();
debugger
if (input.val() == "") {
var acv = $(".k-tooltip-validation[data-for='strAssignedTo']");
acv.text("PhoneNumber is required");
}
return true;
},
}, },
bitClosedYN: { type: "boolean", editable: true, }
}
},
sort: [{ field: "id", dir: "desc" }]
},
requestEnd: function (e) {
if (e.type == "create" || e.type == "update") {
this.read();
}
},
error: function (e) {
//display_kendoui_grid_error(e);
// Cancel the changes
$('#divError').html('<div class="alert alert-danger alert-dismissable">'
+ '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Note cannot be deleted because it is being used.'
+ '</div>');
this.cancelChanges();
},
pageSize: 4,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
pageable: {
refresh: true,
pageSizes: [10, 15, 20, 50, 100]
},
toolbar: [{ name: "create", text: "Add New" }],
editable: {
confirmation: "Are you sure you want to delete this item?",
mode: "inline",
//mode: "incell"
},
scrollable: false,
///////////////////////////code by puja verma//////////////////////
dataBound: function (e) {
var dataItems = this.dataSource.view();
var isFieldPending = false;
var validationErrors = [];
for (var i = 0; i < dataItems.length; i++) {
if (dataItems[i].strNoteText === "") {
isFieldPending = true;
validationErrors.push("Please Save the new record before clicking Next");
break;
}
}
@*////////////////////code by puja verma///////////////////*@
var nextButton = $("#nexttocomplete");
var validationMessage = $("#validationMessageEnterprisenotes1,#validationMessageEnterprisenotes");
if (isFieldPending || validationErrors.length > 0) {
nextButton.prop("disabled", true);
validationMessage.text(validationErrors.join('\n'));
}
else {
nextButton.prop("disabled", false);
validationMessage.text("");
}
},
///////////////////////////code by puja verma//////////////////////
// dataBound: onDataBound,
columns: [
{
title: "Action",
command: [
{
name: "edit",
text: {
edit: '<i style="color:#B60202;" class="fa fa-edit fa-lg"></i>',
update: '<i style="color:#B60202;" class="fa fa-floppy-o" aria- hidden="true"></i>',
cancel: '<i style="color:#B60202;" class="fa fa-close fa-lg"></i>'
}
},
{
name: "destroy",
text: '<i style="color:#B60202;" class="fa fa-trash fa-lg"></i>'
}
],
width: 130
},
{
field: "strNoteText",
title: "Enterprise Note",
width: 300
},
{
field: "strAssignedTo",
title: "Assigned to",
width: 300,
template: '#=strFirstname#',
editor: function (container, options) {
$('<input required name="' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
dataSource: noteList,
dataTextField: "strFirstname",
dataValueField: "strAssignedTo",
valuePrimitive: true,
autoBind: false,
optionLabel: "Select site admin",
height: 500
})
},
},
{
field: "strNextReminderDate",
title: "Reminder Date",
format: "{0:dd/MM/yyyy}",
width: 300
},
{
field: "bitClosedYN",
title: "Status",
width: 100,
//template: "<input type='checkbox' name='bitClosedYN' checked='checked' disabled='disabled' />",
template: "#= (bitClosedYN == true ) ? 'Yes' : 'No' #",
attributes: { class: "ob-fld-boolean" },
}
]
});
our working code is:
$("#EnterpriseNote-grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: {
url: "@Html.Raw(Url.Action("ListEnterpriseNoteData", "Enterprise", new { Id = ViewBag.EnterpriseID }))",
type: "POST",
dataType: "json",
// data: additionalData
}, create: {
url: "@Html.Raw(Url.Action("AddEntrpriseNoteData", "Enterprise", new { newdata = "", Id = ViewBag.EnterpriseID }))",
type: "GET",
dataType: "json",
// data: addAntiForgeryToken
},update: {
url: "@Html.Raw(Url.Action("EditEnterpriseNote", "Enterprise"))",
type: "POST",
dataType: "json",
// data: addAntiForgeryToken
},
destroy: {
url: "@Html.Raw(Url.Action("DeleteEnterpriseNote", "Enterprise"))",
type: "POST",
dataType: "json",
// data: addAntiForgeryToken
},
},
schema: {
data: "Data",
total: "Total",
errors: "Errors",
model: {
id: "Id",
fields: {
strNoteText: {
editable: true, type: "string",
validation: {
required: {
message: 'Note Text is required'
},
}
},
strNextReminderDate : { editable: true, type: "date" },
strFirstname: { editable: false, type: "string" },
strAssignedTo: {
editable: true, type: "string",
validation: {
required: {
message: 'PhoneNumber is required'
},
Assignedvalidation: function (input) {
var trimmedValue = input.val().trim();
debugger
if (input.val() == "") {
var acv = $(".k-tooltip-validation[data-for='strAssignedTo']");
acv.text("PhoneNumber is required");
}
return true;
},
}, },
bitClosedYN: { type: "boolean", editable: true, }
}
},
sort: [{ field: "id", dir: "desc" }]
},
requestEnd: function (e) {
if (e.type == "create" || e.type == "update") {
this.read();
}
},
error: function (e) {
//display_kendoui_grid_error(e);
// Cancel the changes
$('#divError').html('<div class="alert alert-danger alert-dismissable">'
+ '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Note cannot be deleted because it is being used.'
+ '</div>');
this.cancelChanges();
},
pageSize: 4,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
pageable: {
refresh: true,
pageSizes: [10, 15, 20, 50, 100]
},
toolbar: [{ name: "create", text: "Add New" }],
editable: {
confirmation: "Are you sure you want to delete this item?",
mode: "inline",
//mode: "incell"
},
scrollable: false,
///////////////////////////code by puja verma//////////////////////
dataBound: function (e) {
var dataItems = this.dataSource.view();
var isFieldPending = false;
var validationErrors = [];
for (var i = 0; i < dataItems.length; i++) {
if (dataItems[i].strNoteText === "") {
isFieldPending = true;
validationErrors.push("Please Save the new record before clicking Next");
break;
}
}
@*////////////////////code by puja verma///////////////////*@
var nextButton = $("#nexttocomplete");
var validationMessage = $("#validationMessageEnterprisenotes1,#validationMessageEnterprisenotes");
if (isFieldPending || validationErrors.length > 0) {
nextButton.prop("disabled", true);
validationMessage.text(validationErrors.join('\n'));
}
else {
nextButton.prop("disabled", false);
validationMessage.text("");
}
},
///////////////////////////code by puja verma//////////////////////
// dataBound: onDataBound,
columns: [
{
title: "Action",
command: [
{
name: "edit",
text: {
edit: '<i style="color:#B60202;" class="fa fa-edit fa-lg"></i>',
update: '<i style="color:#B60202;" class="fa fa-floppy-o" aria- hidden="true"></i>',
cancel: '<i style="color:#B60202;" class="fa fa-close fa-lg"></i>'
}
},
{
name: "destroy",
text: '<i style="color:#B60202;" class="fa fa-trash fa-lg"></i>'
}
],
width: 130
},
{
field: "strNoteText",
title: "Enterprise Note",
width: 300
},
{
field: "strAssignedTo",
title: "Assigned to",
width: 300,
template: '#=strFirstname#',
editor: function (container, options) {
$('<input required name="' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
dataSource: noteList,
dataTextField: "strFirstname",
dataValueField: "strAssignedTo",
valuePrimitive: true,
autoBind: false,
optionLabel: "Select site admin",
height: 500
})
},
},
{
field: "strNextReminderDate",
title: "Reminder Date",
format: "{0:dd/MM/yyyy}",
width: 300
},
{
field: "bitClosedYN",
title: "Status",
width: 100,
//template: "<input type='checkbox' name='bitClosedYN' checked='checked' disabled='disabled' />",
template: "#= (bitClosedYN == true ) ? 'Yes' : 'No' #",
attributes: { class: "ob-fld-boolean" },
}
]
});