Angular form validation ng-disabled not working

You’re missing ng-model on every field of your form. Keep in mind when you mention ng-model on any form field at that time ng-model creates the extra objects inside form name object with that specific name attribute which then considered while form validation like $error, $valid, $invalid, etc.

As your form name is blgoPost, when angular compile this page,it internally creates the object inside the scope of the name of blgoPost. And the all the input fields which has name & ng-model assign to them gets added inside that blgoPost object. But if you don’t mention ng-model to the form fields then it will never get added inside the blgoPost form object.

HTML

<form role="form" name="blgoPost" novalidate="">
    <input name="first" />
    <div class="form-group">
        <label for="blgoTitle">Title</label>
        <input name="title" type="title" class="form-control" ng-model="test1" placeholder="Technologies of the Future" required="">
        <br>
        <label for="blgoContent">Content</label>
        <textarea name="content" rows="8" type="content" ng-model="test2" class="form-control" placeholder="The technical innovations of the future will be diverse and impactful on the individual......" required=""></textarea>
        <br>
        <label for="blgoPassCode">PassCode</label>
        <input name="passcode" type="passcode" ng-model="test3" class="form-control" placeholder="&#8226;&#8226;&#8226" required="" />
        <br/>
        <button type="submit" class="btn btn-primary" ng-disabled="blgoPost.$invalid">Submit Post</button>
    </div>
</form>

Working Fiddle

Leave a Comment