角度表单验证ng已禁用,无法工作
Angular form validation ng-disabled not working
我正试图在博客文章的表单中使用角度表单验证,更具体地说,是一个禁用了ng的表单。由于一些原因,我无法确定提交按钮没有被禁用,除非所有三个输入字段都有效,否则它应该被禁用。谢谢你的帮助。
这是我的博客模板
<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='•••••••••••••••' required><br>
<button type="submit" class='btn btn-primary' ng-disabled="blgoPost.$invalid">Submit Post</button>
</div>
</form>
</div>
</div>
这是我的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>
这是我的博客控制器
angular.module('Teewinot').controller('BlgoCtrl', function($scope, $http) {
'use strict'
});
表单的每个字段都缺少ng-model
。请记住,当您在任何表单字段上提到ng-model
时,ng-model
会在具有特定name
属性的表单名称对象中创建额外对象,然后在表单验证时考虑这些属性,如$error
、$valid
、$invalid
等。
由于您的表单name
是blgoPost
,所以在angular编译此页面时,它会在blgoPost
名称的范围内内部创建对象。并且所有具有CCD_ 11&分配给它们的ng-model
被添加到blgoPost
对象内部。但是,如果您没有在表单字段中提及ng-model
,那么它将永远不会添加到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='•••' required="" />
<br/>
<button type="submit" class='btn btn-primary' ng-disabled="blgoPost.$invalid">Submit Post</button>
</div>
</form>
工作Fiddle
相关文章:
- 如何防止回车键提交表单,但仍然允许回车工作
- JavaScript表单验证-“;“错误”;不按需要工作
- 谷歌表单-根据分配给谷歌应用程序的工作为商业用户预先填充多项选择列表
- 当阻止Enter键提交AJAX表单时,关注下一个输入是't工作
- jQuery preventdefault提交表单没有'通过js函数提交表单时无法工作
- 使用一个Javascript函数提交多个表单可以在FF中工作,而不需要其他浏览器
- Ajax表单数据phpPOST不工作
- 表单验证工作不正常,在不检查条目的情况下继续
- JavaScript表单返回,但无法正常工作
- 如何使setTimeout脚本在html表单中正常工作
- 表单验证在接近尾声时停止工作
- 谷歌工作表中的按钮,当单击时,会更改特定单元格的背景
- 表单提交没有'调用return false后无法工作
- 多个表单触发到单个工作表
- 如何使谷歌地图在Visual Studio web表单中工作
- 表单验证在 HTML 中工作的 Visualforce 中不起作用
- 为什么我的 Javascript 表单验证无法正常工作
- RubyonRails中的JavaScript表单验证-让JS正常工作,但我该把它放在哪里
- 如何使表单类而不是id的序列化工作
- 图片上传无法在IE中工作,表单未提交