Angular Form Validation $invalid not working -
i trying disable submit button, when fields empty. not working. don't know why not working. saw many blogs, could't figure whats issue.
<form name="createform"> <div class="form-group col-md-6"> <label for="createname">student</label> <select class="form-control" name="student" id="createname" ng- model="createstudent.studentid" ng-options="item.name item in allstudent" required> <option value="" selected disabled>select</option> </select> </div> <div class="form-group col-md-6"> <label for="createclass">class</label> <select class="form-control" name="class" id="createclass" ng- model="createstudent.classid" ng-options="item.number item in allclass" required> <option value="" selected disabled>select</option> </select> </div> </div> <div class="form-group col-md-6 text-md-center"> <label for="createcategory">type of category</label> <select class="form-control" name="category" id="createcategory" ng-model="createstudent.type" ng-options="item.category_type item in allcategoriestypes" required> <option value="" selected disabled>select</option> </select> </div> </div> <div class="row align-items-end justify-content-center"> <div class="form-group col-md-6 text-md-center"> <label for="createteachername">teacher name</label> <input type="text" class="form-control" name="teacher" id="createteachername" ng-model="createstudent.name" placeholder="enter teacher name" required> </div> </div> </div> <div class="text-center pt-1"> <button type="submit" class="btn btn-info px-5" ng- click="create(createstudent)" ng- disabled="createform.$invalid">save</button> </div> </form>
please find working plunker code :
http://plnkr.co/edit/h1loahfnwrxyhwtvmrcw?p=preview
<form name="createform"> <div class="form-group col-md-6"> <label for="createname">student</label> <select class="form-control" name="student" id="createname" ng- model="createstudent.studentid" required> <option value="studentvalue">student name</option> </select> </div><br/> <div class="form-group col-md-6"> <label for="createclass">class</label> <select class="form-control" name="class" id="createclass" ng- model="createstudent.classid" required> <option value="classvalue">class</option> </select> </div><br/> <div class="form-group col-md-6 text-md-center"> <label for="createcategory">type of category</label> <select class="form-control" name="category" id="createcategory" ng-model="createstudent.type" required> <option value="typevalue">category</option> </select> </div><br/> <div class="row align-items-end justify-content-center"> <div class="form-group col-md-6 text-md-center"> <label for="createteachername">teacher name</label> <input type="text" class="form-control" name="teacher" id="createteachername" ng-model="createstudent.name" placeholder="enter teacher name" required> </div> </div><br/> <div class="text-center pt-1"> <label>value returned $invalid :: {{createform.$invalid}}</label><br/><br/> <button type="submit" class="btn btn-info px-5" ng-click="create(createstudent)" ng-disabled="createform.$invalid">save</button> </div> </form>
make sure tags closed , none of fields empty.
Comments
Post a Comment