Angular ng-disabled form validation not working

I am trying to use the angular form validation in my form for a blog post, and more specifically for a forbidden form. For reasons I can’t understand that the submit button is not disabled, where should it be if all three input fields are valid. Thanks for the help.

this is my blog template

<div ng-controller='BlgoCtrl'> <div class='container'> <h1> Teewinot Blgo</h1> <div class="row"> <div class='col-md-12'> <form role='form' name='blgoPost' novalidate> <div class='form-group'> <label for='blgoTitle'>Title</label> <input name='title' type="title" class='form-control' placeholder='Technologies of the Future' required><br> <label for='blgoContent'>Content</label> <textarea name='content' rows='8' type="content" 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" class='form-control' placeholder='&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;' required><br> <button type="submit" class='btn btn-primary' ng-disabled="blgoPost.$invalid">Submit Post</button> </div> </form> </div> </div> 

Here is my index.html

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Teewinot</title> <script src="bower_components/angular/angular.js"></script> <script src="bower_components/jquery/dist/jquery.js"></script> <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="bower_components/angular-route/angular-route.js"></script> <link href="bower_components/bootstrap/dist/css/bootstrap.css" rel="stylesheet"> </head> <body ng-app="Teewinot"> <ng-include src="'app/templates/partials/navbar.html'"></ng-include> <ng-view></ng-view> <!-- angular module defintion and reoutes --> <script src="app/js/app.js"></script> <script src="app/js/routes.js"></script> <!-- controllers --> <script src="app/js/controllers/blog.controller.js"></script> </body> </html> 

This is my blog controller.

 angular.module('Teewinot').controller('BlgoCtrl', function($scope, $http) { 'use strict' }); 
+5
source share
1 answer

You are missing ng-model in every field of your form. Keep in mind that when ng-model mentioned in any form field at this time, ng-model creates additional objects inside the form name object with this particular name attribute, which is then considered during form validation, for example $error , $valid , $invalid etc.

Since your form name blgoPost , when angular blgoPost this page, it internally creates an object inside the blgoPost . And all input fields that have name and ng-model are assigned to them, are added inside this blgoPost object. But if you do not specify ng-model in the form fields, it will never be added inside the blgoPost form blgoPost .

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 script

+20
source

Source: https://habr.com/ru/post/1213553/


All Articles