javascript - angularjs $valid not working on fields -


i new angularjs.

i have 2 buttons on form , 1 save , other test connection button.

<td align="left" colspan="0" >     <input class="form-control" title="specifies ip address of sip trunk ethernet connection." placeholder="xxx.xxx.xxx.xxx"              style="display: inline-block;display:block;white-space: nowrap;overflow: hidden;" type="text"              name="pabxipaddress" id="pabxipaddress" ng-model="usersetup.pabxipaddress" required ng-pattern='patternpresent' > </td> <td>     <span class="error" ng-show="(testipofficeflag || submitted) && usersetupform.pabxipaddress.$error.required">         <label style="color: red;">required!</label>     </span>     <span class="error" ng-show='(testipofficeflag || submitted) && usersetupform.pabxipaddress.$error.pattern'>         <label style="color: red;">invalid ip address!</label>     </span> </td> 

now in js file when like, $scope.usersetup.pabxipaddress.$valid dynamic testing gives me

typeerror: cannot read property '$valid' of undefined 

when alert $scope.usersetup.pabxipaddress displays data correctly.

how check whether individual field correct , passed constraints attached it.

the valid property not part of model value... try

$scope.usersetupform.postdail.$valid 

where usersetupform name of form , postdail name of input element.


var app = angular.module('my-app', [], function() {    })    app.controller('appcontroller', function($scope) {      $scope.check = function() {      $scope.validity = {        field1: $scope.myform.myfield1.$valid,        field2: $scope.myform.myfield2.$valid,        field3: $scope.myform.myfield3.$valid      }    };  })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  <div ng-app="my-app" ng-controller="appcontroller">    <form name="myform" novalidate>      <div>        <input type="number" name="myfield1" ng-model="formdata.myfield1" required class="numbers-only-for" minvalue="1" maxvalue="45">      </div>      <div>        <input type="text" name="myfield2" ng-model="formdata.myfield2" required>      </div>      <div>        <input type="text" name="myfield3" ng-model="formdata.myfield3" required>      </div>      <button ng-click="check()">check</button>    </form>    <pre>{{formdata | json}}</pre>    <pre>{{validity | json}}</pre>  </div>


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -