I try to validate a form productForm
by using AngularJS directives, so I try:
<form id="productForm" name="productForm" novalidate>
<div style="width: 100%; margin-top: 15px; float: right; ">
<label style="width:103px;float:right" class="col-sm-2" for="ProductName">ProductName: </label>
<div style="float:right" class="col-sm-5">
<input ng-required="true" class="form-control" style="float:right" type="text" id="ProductName" name="ProductName" ng-model="modal.ProductName" value="" />
</div>
<div style="float:right" class="col-md-7" >
<span class="help-block" ng-if="productForm.ProductName.$error.required && productForm.ProductName.$dirty && productForm.ProductName.$touched "> Name is Must</span>
</div>
</div>
<button class="btn" style="background-color: #ed9c28;" type="button" ng-click="Save()" ng-disabled="productForm.$invalid">Save</button>
</form>
In this way the problem is: when user touch the ProductName
and then it lost focus, the required message didn't show( it just was shown when user type in the input and then clear whole text from the input, but I want to show error message when the input is empty), i try to use productForm.ProductName.$touched
in ng-if
of error message for do it, but it doesn't work, How can I do it?