i validate the the text box entry by checking the data existence in database . I write a json validation function in custom validation area .. and return proper data and validation also work . But it not show validation message when i first time escape the textbox ,It show wthen i click in text box 2nd time and escape again.. Please find put the reason and help me to do remote validation.
jQUERY
-----------
<script language="javascript" type="text/javascript">
var b1 = new Boolean(1);
var b2 = new Boolean(1);
var R_rank=null;
$(document).ready(function () {
//Culture Declaration for Date Validation
kendo.culture("en-GB");
//KendoUi Validation
var validatable = $("#ApplicationNo").kendoValidator({
onfocusout: false,
onkeyup: false,
rules: {
ApplicationNo: function (input) {
$.post("/Home/CheckAppNo", { ApplicationNo: $("#ApplicationNo").val() }, function (data) { b1 = data; })
return b1;
}
},
messages: {
ApplicationNo: "Already Exist"
}
}).data("kendoValidator");
var validatable = $("#ReferredBy").kendoValidator({
onfocusout: false,
onkeyup: false,
rules: {
//ApplicationNo: function (input) { return CheckApplicationNo(); }input.val() === "2";
ReferredBy: function (input) {
$.post("/Home/ReferrerDetails", { InternalCode: $("#ReferredBy").val() }, function (data) {
R_rank = data.R_rank;
if (R_rank == null) { b2 = false; }
else { b2 = true; }
})
return b2;
}
},
messages: {
ReferredBy: "This is not a valid code "
}
}).data("kendoValidator");
//KendoUi Validation in submit button click
var validatable = $(".k-content").kendoValidator().data("kendoValidator");
$("#SubmitAgent").click(function () {
if (validatable.validate()) {
}
else {
//alert("Check The Data.");
e.preventDefault();
}
});
function CheckApplicationNo(input1) {
return {
b1: $.post("/Home/CheckAppNo", { ApplicationNo: $(input1).val() }, function (data) { return data; })
}
}
});
</script>
CSHTML
---------------
<tr>
<td class="EditlableTD">
@Html.LabelFor(model => model.BranchCode)
</td>
<td class="EditTextBoxTD">
@(Html.Kendo().DropDownList()
.Name("BranchCode")
.OptionLabel("Select Branch...")
.DataTextField("BranchName")
.DataValueField("ID")
//.BindTo(ViewBag.Branch)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("ShowBranch", "Home");
});
})
)
@* @Html.ValidationMessageFor(model => model.BranchCode)*@
@* <span style="color:Red">Name</span>*@
</td>
</tr>
<tr>
<td class="EditlableTD">
@Html.LabelFor(model => model.ReferredBy)
</td>
<td class="EditTextBoxTD">
<input type="text" id="ReferredBy" name="ReferredBy" class="k-textbox" />
<span id="R_name" style="color: red">
</span><span id="R_rank" style="color: red"></span><input type="hidden" id="R_Ranks" name="R_Ranks" />
</td>
</tr>
<tr>
<td class="EditlableTD">
Rank
</td>
<td class="EditTextBoxTD">
<script>
function filterRank() {
return {
R_Ranks: $("#R_Ranks").val()
};
}
</script>
@(Html.Kendo().DropDownList()
.Name("Rank")
.OptionLabel("Select Rank...")
.DataTextField("Rk_Name")
.DataValueField("Rk_InternalCode")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("ShowSelectedRank", "Home")
.Data("filterRank");
})
.ServerFiltering(true);
})
.Enable(true)
.AutoBind(false)
//.CascadeFrom("BranchCode")
.HtmlAttributes(new {style="width:200px;" })
)
@* <span style="color:Red">Name</span>*@
</td>
</tr>
<tr>
<td class="EditlableTD">
@Html.LabelFor(model => model.ApplicationNo)
</td>
<td class="EditTextBoxTD">
<input id="ApplicationNo" name="ApplicationNo" class="k-textbox" />
</td>
</tr>
jQUERY
-----------
<script language="javascript" type="text/javascript">
var b1 = new Boolean(1);
var b2 = new Boolean(1);
var R_rank=null;
$(document).ready(function () {
//Culture Declaration for Date Validation
kendo.culture("en-GB");
//KendoUi Validation
var validatable = $("#ApplicationNo").kendoValidator({
onfocusout: false,
onkeyup: false,
rules: {
ApplicationNo: function (input) {
$.post("/Home/CheckAppNo", { ApplicationNo: $("#ApplicationNo").val() }, function (data) { b1 = data; })
return b1;
}
},
messages: {
ApplicationNo: "Already Exist"
}
}).data("kendoValidator");
var validatable = $("#ReferredBy").kendoValidator({
onfocusout: false,
onkeyup: false,
rules: {
//ApplicationNo: function (input) { return CheckApplicationNo(); }input.val() === "2";
ReferredBy: function (input) {
$.post("/Home/ReferrerDetails", { InternalCode: $("#ReferredBy").val() }, function (data) {
R_rank = data.R_rank;
if (R_rank == null) { b2 = false; }
else { b2 = true; }
})
return b2;
}
},
messages: {
ReferredBy: "This is not a valid code "
}
}).data("kendoValidator");
//KendoUi Validation in submit button click
var validatable = $(".k-content").kendoValidator().data("kendoValidator");
$("#SubmitAgent").click(function () {
if (validatable.validate()) {
}
else {
//alert("Check The Data.");
e.preventDefault();
}
});
function CheckApplicationNo(input1) {
return {
b1: $.post("/Home/CheckAppNo", { ApplicationNo: $(input1).val() }, function (data) { return data; })
}
}
});
</script>
CSHTML
---------------
<tr>
<td class="EditlableTD">
@Html.LabelFor(model => model.BranchCode)
</td>
<td class="EditTextBoxTD">
@(Html.Kendo().DropDownList()
.Name("BranchCode")
.OptionLabel("Select Branch...")
.DataTextField("BranchName")
.DataValueField("ID")
//.BindTo(ViewBag.Branch)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("ShowBranch", "Home");
});
})
)
@* @Html.ValidationMessageFor(model => model.BranchCode)*@
@* <span style="color:Red">Name</span>*@
</td>
</tr>
<tr>
<td class="EditlableTD">
@Html.LabelFor(model => model.ReferredBy)
</td>
<td class="EditTextBoxTD">
<input type="text" id="ReferredBy" name="ReferredBy" class="k-textbox" />
<span id="R_name" style="color: red">
</span><span id="R_rank" style="color: red"></span><input type="hidden" id="R_Ranks" name="R_Ranks" />
</td>
</tr>
<tr>
<td class="EditlableTD">
Rank
</td>
<td class="EditTextBoxTD">
<script>
function filterRank() {
return {
R_Ranks: $("#R_Ranks").val()
};
}
</script>
@(Html.Kendo().DropDownList()
.Name("Rank")
.OptionLabel("Select Rank...")
.DataTextField("Rk_Name")
.DataValueField("Rk_InternalCode")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("ShowSelectedRank", "Home")
.Data("filterRank");
})
.ServerFiltering(true);
})
.Enable(true)
.AutoBind(false)
//.CascadeFrom("BranchCode")
.HtmlAttributes(new {style="width:200px;" })
)
@* <span style="color:Red">Name</span>*@
</td>
</tr>
<tr>
<td class="EditlableTD">
@Html.LabelFor(model => model.ApplicationNo)
</td>
<td class="EditTextBoxTD">
<input id="ApplicationNo" name="ApplicationNo" class="k-textbox" />
</td>
</tr>