- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
password
指令。 但是,如果任何验证失败,我希望即使该字段不在焦点上也能看到所有验证。下面是我的表单组片段。
<div class="form-group">
<label for="inputPass" class="col-sm-3 control-label text-sm text-left">Password</label>
<div class="col-sm-9">
<input type="password" placeholder="Password"
class="form-control" ng-model="registerAccount.password"
required name="inputPass" id="inputPass"
password ng-blur="form.inputPass.$invalid ? return: form.inputPass.$setPristine">
<div ng-show="form.inputPass.$dirty" class="help-block">
<p class="text-danger" ng-show="form.inputPass.$error.required">
Password is required.
</p>
<p ng-class="form.inputPass.$error.invalidLength ? 'text-danger' : 'text-success'">
Password should be atleast 8 characters.
</p>
</div>
</div>
</div>
以下是我的指令
'use strict';
angular.module('nileLeApp')
.directive('password', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function ($scope, $element, $attrs, ngModelCtrl) {
$scope.$watch($attrs.ngModel, function (value) {
if (value) {
var length = (value.length >= 8);
ngModelCtrl.$setValidity('invalidLength', length);
}
});
}
};
});
当焦点离开字段时,验证列表仍然显示出来。我原以为它会被隐藏,因为该字段被设置为原始状态。有任何想法吗 ?我希望它类似于 https://dl.dropboxusercontent.com/u/636000/password_verification/index.html 中的密码字段.当用户键入密码时,验证以红色/绿色反射(reflect)。
最佳答案
您没有调用 $setPristine
方法。应该是 form.inputPass.$setPristine()
:
ng-blur="form.inputPass.$invalid ? return: form.inputPass.$setPristine()"
或更简洁的变体:
ng-blur="form.inputPass.$valid && form.inputPass.$setPristine()"
关于javascript - ngBlur 上的 Angular setPristine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34783849/
我正在尝试创建一个基本的登录表单,当加载页面并提交表单时,表单将重置。 我不断收到以下错误: TypeError: Cannot read property '$setPristine' of und
我有一个包含多个子表单的父表单(例如 http://jsfiddle.net/riemersebastian/9zr00ear/3/ ) 当用户更改任何字段时,相应的子表单和父表单都会获取类 ng-d
我正在尝试对表单中的单个输入字段使用 setPristine 方法。有多种方法可以对整个表单执行此操作,但我只想对表单中的一个输入字段执行此操作。我该怎么做? 我这样试过 $scope.merchan
**** 注意我删掉了一些其他功能,以便可以更快地阅读代码。我无法清除表格。当我单击具有取消功能的按钮时。我以为我可以设置一个默认表单,但这并没有什么不同。
First Name This is required.
提交表单后,我一直在努力重置表单。有人发布了此Here我想让它发挥作用但没有成功。这是我的My Code Example . $scope.form.$setPristine(); 未将 Pristi
我发现下面的代码很奇怪。 dataSvc.saves 回调之后,vm.bookDetails = {};和 vm.bookForm.$setPristine 的用途? angular.module('
尝试重置表单时,出现错误无法读取未定义的属性“$setPristine”。 我的 Controller : formApp.controller('FormController', ['$scope'
我正在尝试使用 $setPristine() 重置表单。 $scope.resetDataEntryForm = function() { $scope.dataEntryForm.$setP
我想做简单的事情,清理 $scope.user 字段,并且不会因此而出现错误。 if ($scope.contactForm.$valid) { $scope.user = {}; $
当我提交表单时,我希望某些输入元素为 $setPristine。因为在提交表单后,我将清空绑定(bind)到输入元素的模型,以防用户完全可以再次输入新内容。但是,一旦我清空模型,输入元素也会清空,因此
任何人都可以帮助使用随附的 Plunker 吗?? 只需提交仅输入一个必填字段的表单。这将触发验证错误。然后重置同时调用 setPristine 和 setUntouched 的表单 - 两者都应该重
我正在尝试使用 Angular 的内置表单函数,特别是 setPristine() 来清除用户提交的表单。我的 Controller 可以访问 $scope.newForm(我的表单)及其所有方法,但
当我运行以下代码来重置表单时出现错误: $scope.saveFormData = function () { $scope.testForm.$setPristine();
我有一个带有密码字段的表单,我为其实现了一个password 指令。 我目前只实现了 1 项验证,但我有一个现场验证列表。 我希望它们分别显示为红色或绿色,具体取决于有效/无效 - 当用户开始在字段中
我正在尝试将当前的 api 调用写入可在 ApiService 工厂内重用的工厂。但是,我似乎无法清除表格。 那么,我能做些什么来使clearForm函数按原样工作。 S
我有以下代码: 这是有效的,当我点击一个提交类型的按钮时,就会调用 modalSubmit 函数。 但是我想在我的 Controller 中做到这一点: $scope.mod
我有一个表单不允许您选中第一个条目上的复选框,这很奇怪。这几乎就像它没有记录点击一样。 但是,如果您提交表单并在提交第一个表单后尝试选中相同的复选框,则它允许您选中这些复选框。这是为什么? 这就是我的
我正在用 Angular Material 制作一个简单的表格来添加帖子,我还有一个取消按钮来清除表格。我尝试使用 $setPristine() 但在调用 clearForm 函数后输入字段仍显示为红
当我尝试使用 TypeScript 中的 form.$setPristine 时,它不起作用并且调试显示 form 未定义。根据我的阅读,$scope.formName.$setPristine()
我是一名优秀的程序员,十分优秀!