I'm struggling create validation for inputs in jQuery. I have a btn to create a row. When I click this btn, you will see a pop up page which include 2 text box and 1 dropdown. I want to check if these tow text box is not empty then its going to submit. This is my creating btn which open pop up:
<div class="col-lg-12 panel">
<a href="#" class="btn btn-primary" data-toggle="modal" data-target="#editModal">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> @Resource.Add_new_item
</a>
</div>
And this is what in this pop up:
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
@using (Html.BeginForm("Edit", "ApplicationDetailList", new {page = Model.PageNumber,filter.ListType, filter.PackageName }, FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addModalLabel">@Resource.Add_new_item </h5>
</div>
<div class="modal-body">
<div class="form-group">
<label>@Resource.Application_category_tittle *</label>
<input name="id" id="id" class="form-control" style="direction: ltr;"/>
@*@Html.ValidationMessageFor(m => m[0].Id);*@
</div>
<div class="form-group">
<label>@Resource.List_type *</label>
@Html.DropDownList("listType", ApplicationDetailListType.Solr.ToSelectListItems(false, filter.ListType), new { @class = "form-control"})
@*<input name="tags" class="form-control" style="direction: ltr;"/>*@
</div>
<div class="form-group">
<label>@Resource.Package_name *</label>
<input name="packageName" class="form-control" style="direction: ltr;"id="packageName" />
@*@Html.ValidationMessageFor(m=>m[0].PackageName);*@
</div>
<label id="validation">
</label>
<div class="form-group">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success btn-edit-save">@Resource.Save</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">@Resource.Cancel</button>
</div>
</div>
}
</div>
</div>
And this this is my section script which I made function:
var edit = $("#editModal");
// var packageName = $("#packageName").val();
//var id = $("#id").val();
//packageName.length > 0 && id.length > 0 ?
$(".btn-edit-save").click(function() {
$("form", edit).submit();
});
the problem is here:
$(".btn-edit-save").click(function() {
$("form", edit).submit();
});
I don't want to submit if inputs are empty and just show message they are empty. Many thanks