angularjs-forms

ng-required not working when submitting a form

混江龙づ霸主 提交于 2020-01-03 16:56:32
问题 I have the following code in an input text box with the required attribute, but when I tab off of the field or submit the form, it doesn't stop the form from submitting and informing the user the field is required. <div class="col-sm-8"> <input type="text" ng-required="true" class="form-control" placeholder="Enter Total Amount" id="txtTotalAmount" ng-model="formCtrl.AddCheckDeposit.TotalAmount" /> </div> What do I need to do to make the required directive to work? 回答1: For that you should

Using $setValidity inside a Controller

末鹿安然 提交于 2019-12-20 08:26:59
问题 I am trying to do some validation on file change. Here is my code: View/Template <input type="file" name="file" id="file" onchange="angular.element(this).scope().setFile(this)" required /> <span class="error" ng-show="myForm.file.$error.required">Error</span> <span class="error" ng-show="myForm.file.$error.size">Selected file is too large</span> <span class="error" ng-show="myForm.file.$error.filetype">Unsupported File type</span> Controller angular.module("myapp").controller("myctrl",

Angular dynamic ng-model name

无人久伴 提交于 2019-12-11 19:57:38
问题 <div class="pw-form-control-text" id="disclosureQuestionsPrepopulate" name="disclosureQuestionsPrepopulate" ng-repeat="type in (prepopulatingFieldData|prepopulateValue:'c2a39346-9e95-e411-bd87-00155d005107')" > <div > <input name="{{type.Id}}" ng-model="formData.disclosureQuestionsPrepopulate"($index + 1) ng-click="option.selected = true" type="radio" value=true >Yes</input> </input> here what I want to do is my ng-model name should be like this formData.disclosureQuestionsPrepopulate1",

Angularjs directive to make form dirty without ng-model

我与影子孤独终老i 提交于 2019-12-11 13:28:48
问题 I am using Angular 1.5.1. I have a checkbox on my form. I do not care about the truth/false indicator of the checkbox being checked/unchecked and so I do not want ng-model on it. What I care for is: when checkbox is unchecked, I delete a specific array from my model when checkbox is checked, I add an empty array back to my model So I have created a directive that provides me with this functionality, very simple: .directive('cbOnChecked', function() { return { restrict: 'A', link: function

Using $setValidity inside a Controller

匆匆过客 提交于 2019-12-02 15:41:58
I am trying to do some validation on file change. Here is my code: View/Template <input type="file" name="file" id="file" onchange="angular.element(this).scope().setFile(this)" required /> <span class="error" ng-show="myForm.file.$error.required">Error</span> <span class="error" ng-show="myForm.file.$error.size">Selected file is too large</span> <span class="error" ng-show="myForm.file.$error.filetype">Unsupported File type</span> Controller angular.module("myapp").controller("myctrl", function($scope) { $scope.setFile = function(element) { $scope.$apply(function($scope) { var fileObject =

Angular form not working in a table

时光总嘲笑我的痴心妄想 提交于 2019-12-01 18:05:10
I created a working form placed in a div below a table; <div class="row"> <form class="form-signin" ng-submit="controller.add.save()"> <h2 class="form-signin-heading">Add an item:</h2> <label for="inputName" class="sr-only">Name</label> <input type="text" name="name" id="inputName" class="form-control" placeholder="Name" required autofocus ng-model="controller.add.name"> <label for="inputDescription" class="sr-only">Description</label> <textarea name="description" id="inputDescription" class="form-control" placeholder="Description" ng-model="controller.add.description"> </textarea> <button

Angular form not working in a table

拟墨画扇 提交于 2019-12-01 17:22:29
问题 I created a working form placed in a div below a table; <div class="row"> <form class="form-signin" ng-submit="controller.add.save()"> <h2 class="form-signin-heading">Add an item:</h2> <label for="inputName" class="sr-only">Name</label> <input type="text" name="name" id="inputName" class="form-control" placeholder="Name" required autofocus ng-model="controller.add.name"> <label for="inputDescription" class="sr-only">Description</label> <textarea name="description" id="inputDescription" class=

AngularJs: Required field validation and highlight for dynamic rows of HTML table with contenteditable

好久不见. 提交于 2019-12-01 15:26:41
问题 I have an HTML table as below: <tbody> <tr ng-repeat="r in targetTable.rows"> <td contenteditable="true" class=""></td> <td contenteditable="true" ng-repeat="column in targetTable.columns" ng-model="r[column.id]" ng-blur="!r.id? addNewRow(r[column.id], r): undefined"> </td> </tr> </tbody> I am using the contenteditable directive to make the cells editable. app.directive('contenteditable', ['$sce', function($sce) { return { restrict: 'A', require: '?ngModel', link: function(scope, element,

Angular form is $valid when all inputs are blank, why?

岁酱吖の 提交于 2019-12-01 04:21:12
My form is showing up as valid even though all of my input fields are blank. I have the required keyword in the input fields. <!DOCTYPE html> <html ng-app="myApp"> <head> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/css/materialize.min.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script type="text/javascript" src="/components/angular/angular.min.js"></script> <script type="text/javascript" src="/js/app.js"></script> </head> <body> <main> <div class="container"> <div class="row"> <section ng-controller=

Angular form is $valid when all inputs are blank, why?

久未见 提交于 2019-12-01 01:14:34
问题 My form is showing up as valid even though all of my input fields are blank. I have the required keyword in the input fields. <!DOCTYPE html> <html ng-app="myApp"> <head> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/css/materialize.min.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script type="text/javascript" src="/components/angular/angular.min.js"></script> <script type="text/javascript" src="/js