json - Possible bug in angular pristine -
my hope @ fault here , not angular. building dynamic form using ng-repeat , when call form scope tells me pristine true (even when it's not). looks plunker can handle form pristine not dynamic input pristine. have more complex code have boiled down below. results getting when type in "asdf" first input are:
$scope.formname.$pristine = false;<br> $scope.formname.inputname.$modelvalue = "asdf";<br> $scope.formname.inputname.$pristine = true;<br> $scope.formname.inputname.$viewvalue = "asdf";<br> $scope.formname.inputname.$$rawmodelvalue = "asdf";
doesn't make sense how form pristine true input pristine false.
here basic code:
<html ng-app="app"> <head> <link rel="stylesheet" href="style.css"> <script data-semver="1.2.13" src="http://code.angularjs.org/1.2.13/angular.js" data-require="angular.js@1.2.x"></script> <script src="script.js"></script> </head> <body ng-controller="mainctrl"> <form name="formname"> <div ng-repeat="item in items"> {{item['-desc']}} <input type="text" name="item['-id']"> <a href="" ng-click="clickme(item, $index)">+</a> </div> </form> {{ispristine}} </body> </html> var app = angular.module('app', []); app.controller('mainctrl', function($scope) { $scope.formname = {}; $scope.items = [ { "-id": "1", "-name": "fname", "-desc": "first name" }, { "-id": "2", "-name": "lname", "-desc": "last name" }, { "-id": "3", "-name": "doc_dte", "-desc": "doc date" }, { "-id": "4", "-name": "ssn_tin", "-desc": "ssn or tin" } ]; $scope.clickme = function clickme(item, index) { var someitem = item['-id]; $scope.ispristine = $scope.formname[someitem].$pristine; } });
as final result need pristine of dynamically created input if typed field can generate row user if want second/third first name... if type nothing cannot create row. have row code working doesn't ng-hide plus sign when input not pristine.
i figured out. reason when using dynamic ng-model , stopping scope.form recognizing scope.form.input. not sure why happens think it's me bug rather angular bug.
Comments
Post a Comment