Hi Experts,
I am using kendo-validator to validate the input controls like (Textbox, Dropdown etc.)
The validation for empty field is working if i move one control to another control using Tab.
I needed that all validation for empty fields should triggered on form submit, not on Tab.
The sample code is below.
<div class="row">
<div class="col-md-4">
<form id="addfacility" asp-action="Add" kendo-validator="true">
<div asp-validation-summary="ModelOnly" class="text-danger" style="width:900px;"></div>
<div class="form-group" style="width:400px;">
<label asp-for="Name" class="control-label"></label>
<input asp-for="Name" class="form-control" maxlength="200" style="width:300px" />
@*<span asp-validation-for="Name" class="text-danger" style="width:500px"></span>*@
</div>
<div class="form-group" style="width:400px;">
<label asp-for="Address.Address1" class="control-label"></label>
<input asp-for="Address.Address1" class="form-control" maxlength="100" style="width:300px" />
@*<span asp-validation-for="Address.Address1" class="text-danger"></span>*@
</div>
<div class="form-group" style="width:400px;">
<label asp-for="Address.Address2" class="control-label"></label>
<input asp-for="Address.Address2" class="form-control" maxlength="100" style="width:300px" />
@*<span asp-validation-for="Address.Address2" class="text-danger"></span>*@
</div>
<div class="form-group" style="width:400px;">
<label asp-for="Address.City" class="control-label"></label>
<input asp-for="Address.City" class="form-control" maxlength="50" style="width:200px" required="required" title="City field is required."/>
@*<span asp-validation-for="Address.City" class="text-danger"></span>*@
</div>
<div class="form-group">
<label asp-for="Address.State" class="control-label"></label>
@(Html.Kendo().DropDownListFor(x => x.SelectedStateId)
.OptionLabel("--Please Select--")
.DataTextField("Name")
.DataValueField("EntityId")
.BindTo(Model.StateList)
.HtmlAttributes(new { required = "required", validationmessage = "The State field is Required.", @class = "form-control", style = "width: 200px;" })
)
@*<span asp-validation-for="SelectedStateId" class="text-danger"></span>*@
</div>
<div class="form-group">
<label asp-for="Address.Zip" class="control-label"></label>
<input asp-for="Address.Zip" class="form-control" maxlength="5" style="width:75px" />
@*<span asp-validation-for="Address.Zip" class="text-danger"></span>*@
</div>
<div class="form-group">
<label asp-for="Address.County" class="control-label"></label>
<input asp-for="Address.County" class="form-control" maxlength="50" style="width:200px" />
@*<span asp-validation-for="Address.County" class="text-danger"></span>*@
</div>
<div class="form-group" style="width:400px;">
<label asp-for="Phone" class="control-label"></label>
@(Html.Kendo().MaskedTextBoxFor(x => x.Phone)
//.Name("Phone")
.Mask("000-000-0000")
.HtmlAttributes(new { @class = "form-control", style = "Width:130px" }
)
//.Value(Model.PhoneNumber.Number)
)
<span asp-validation-for="Phone" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Ext" class="control-label"></label>
<input asp-for="Ext" class="form-control" maxlength="4" style="width:75px" />
@*<span asp-validation-for="Ext" class="text-danger"></span>*@
</div>
<div class="form-group">
<label asp-for="Email" class="control-label"></label>
<input asp-for="Email" class="form-control" style="width:300px" maxlength="255"/>
@*<span asp-validation-for="Email" class="text-danger"></span>*@
</div>
<div class="form-group">
<label asp-for="Status" class="control-label"></label>
@(Html.Kendo().DropDownListFor(x => x.SelectedStatusId)
//.Name("Status")
.DataTextField("Text")
.DataValueField("Value")
.BindTo(Model.StatusList)
.HtmlAttributes(new { @class = "form-control", style = "width: 130px;" })
//.Value(Convert.ToString((int)Model.Status))
)
@*<span asp-validation-for="SelectedStatusId" class="text-danger"></span>*@
</div>
<div class="form-group">
<label asp-for="Organization" class="control-label"></label>
@(Html.Kendo().DropDownListFor(x => x.SelectedOrganizationId)
.OptionLabel("--Please Select--")
.DataTextField("Name")
.DataValueField("EntityId")
.BindTo(Model.OrganizationList)
.HtmlAttributes(new { required = "required", validationmessage = "The Organization field is Required.", @class = "form-control", style = "width: 300px;" })
)
@*<span asp-validation-for="SelectedOrganizationId" class="text-danger"></span>*@
</div>
<div class="form-group">
<label asp-for="FacilityType.Name" class="control-label"></label>
@(Html.Kendo().DropDownListFor(x => x.SelectedFacilityTypeId)
.OptionLabel("--Please Select--")
.DataTextField("Name")
.DataValueField("EntityId")
.BindTo(Model.FacilityTypeList)
.HtmlAttributes(new { required = "required", validationmessage = "The FacilityType field is Required.", @class = "form-control", style = "width: 300px;" })
)
@*<span asp-validation-for="FacilityType" class="text-danger"></span>*@
</div>
<div class="form-group">
<br />
<input type="submit" value="Add" class="btn btn-primary" />
<input type="button" value="Cancel" class="btn btn-primary" onclick="location.href = '@Url.Action("Index", "Facility")'" />
</div>
</form>
</div>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
Please help !!!
Thanks & Regards
Lalit Narayan