Thank you, Alex.
We have a requirement that addFilePopup() , Edit, Delete will be disabled for closed event dates. which is determined by EndServiceDate. I have assinged an ID for addFilePopup() and wrote function which checks the EndServiceDate based on it disables addFilePopup() , Edit, Delete. along with this Autocomplete function is written for SelectedDocType field in addFilePopup().
Every thing works fine. Now I have the requirement to achieve same Auto complete/Validation for SelectedDocType when user wants to Edit (Popup) a row. Below is the complete Jquery function. Let me know if you need any other details. Thanks.
<style>
.form-horizontal .control-label {
text-align: left !important;
}
</style>
<script>
$(document).ready(function() {
$("#txtScanDate").kendoDatePicker();
$("#txtDateSubmitted").kendoDatePicker();
$("#txtDateSigned").kendoDatePicker();
$("#txtDateCreated").kendoDatePicker();
var validator = $("form").kendoValidator({
rules: {
upload: function(input) {
if (input[0].type === "file") {
return input.closest(".k-upload").find(".k-file").length;
}
return true;
},
custom:function(input){
if(input.is("[name=SelectedDocType]")){
var isValidDocType=ValidateDocumentType();
return isValidDocType;
}
//Add any more conditions for custom validation here
return true;
}
},
messages: { upload:"Please select a file",
custom:function(input){
if(input.is("[name=SelectedDocType]"))
{ return "Invalid Document Type selected";}
//Add any more conditions for custom validation here
}
}}).data("kendoValidator");
var myWindow = $("#window");
function onClose() {
}
myWindow.kendoWindow({
width: "900px",
title: "Add new file",
visible: false,
actions: [
"Pin",
"Minimize",
"Maximize",
"Close"
],
close: onClose
}).data("kendoWindow").center();
function load(e) {
loadImage(
e.target.files[0],
function(img) {
$("#divImg").html(img);
},
{ maxWidth: 600 }
);
}
$("input[type='file']").on("change", load);
var endServiceDate = @Html.Raw(Json.Encode(Model.EndServiceDate));
if (endServiceDate == null || !endServiceDate) {
$("#addNewFile").attr('disabled', true);
} else {
$("#addNewFile").attr('disabled', false);
}
$("#txtDocType").kendoAutoComplete({
dataSource: new kendo.data.DataSource({
type: "json", // specifies data protocol
pageSize: 3,//This is to set search limit
serverFiltering: true,
transport: {
read: '@Url.Action("GetDocumentTypes", "Home")',
parameterMap:function(){
return {filterKey:$("#txtDocType").data("kendoAutoComplete").value()};
}
},
}),
dataTextField:"Type",
filter: "contains",
minLength: 3,//This is to set minimum character length for autocomplete
});
});
function ValidateDocumentType(){
var isValidDocType=true;
$.ajax({
data:{documentType:$("#txtDocType").val()},
url:'@Url.Action("GetDocumentType", "Home")',
async: false,
success:function(data) {
if(data==false)
isValidDocType=false;
complete=true;
},
});
return isValidDocType;
}
function onAdditionalData() {
return {
text: $("#products").val()
};
}
function addFilePopup() {
if ($("#addNewFile").attr('disabled') !== "disabled") {
$("#window").data("kendoWindow").center().open();
}
//if (endServiceDate == null || !endServiceDate) {
// $("#window").data("kendoWindow").center().open();
//}
}
function onRemove(e) {
$("#divImg").html('');
}
function onSelect(e) {
setTimeout(function() {
$("input[type='file']").on("change", function(e) {
loadImage(
e.target.files[0],
function(img) {
$("#divImg").html(img);
},
{ maxWidth: 600 }
);
});
}, 2000);
}
function onSuccess(e) {
}
function onDataBound(e) {
var grid = $("#grid").data("kendoGrid");
var endServiceDate = @Html.Raw(Json.Encode(Model.EndServiceDate));
if (endServiceDate == null || !endServiceDate) {
grid.table.find(".k-grid-edit").prop('disabled', true).attr('disabled', true);
grid.table.find(".k-grid-delete").prop('disabled', true).attr('disabled', true);
} else {
grid.table.find(".k-grid-edit").prop('disabled', false).attr('disabled', false);
grid.table.find(".k-grid-delete").prop('disabled', false).attr('disabled', false);
}
}