ng pattern - $scope.var giving undefined in angularjs -


i using angularjs client side validation on textbox need input alphanumeric chars only. if textbox left empty or non-alphanumeric char entered, submitform sends 'false' js desired problem doesn't pass non-alphnumeric char (in scope).

jsp file:

    <form name="addressform" method="post"  ng-submit="submitform(addressform.$valid)" novalidate>     ..     <input ng-model="address" type="text"  **ng-pattern**="/^[a-za-z0-9 ]*$/" required="true"/> 

js file:

$scope.submitform= function(isvalid){ var inputaddr = $scope.address; alert(inputaddr);  //coming undefined ... 

now when input alphanumeric character in input box 'address' in jsp gives me undefined on alerting in js (probably because of pattern filters char being non-alphanumeric). if remove ng-pattern, passes submitform passes 'true' if every input "as expected". reason want access $scope.address check , value , display different error message "empty" , "non-alphanumeric" validation.

any appreciated !

when model not valid, value not assigned model. if want see user has typed, need check $viewvalue:

you must add name attribute input, change input html to:

<input ng-model="address" type="text" name="address" ng-pattern="/^[a-za-z0-9 ]*$/" required="true"/> 

and change submit function to

$scope.submitform = function(isvalid) {     console.log($scope.addressform.address.$viewvalue);   } 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -