angularjs - setPristine to clear the form not working -



angularjs - setPristine to clear the form not working -

i trying clear form info , state of form when user clicks on submit button. plunker problem is:

http://plnkr.co/edit/9jfafkjt4cesoknlkzbf?p=preview

the html is:

<div id="contactform" class="container"> <form class="horizontal" name="userform" data-ng-submit="sendemail(user)"> <div class="col-md-12"> <div class="pull-left"> <div class="form-group"> <label for="companyname">frima</label> <input type="text" id="companyname" class="form-control" title="firma" name="companyname" pattern="[a-za-z0-9ÀÁÄÈÉËÌÍÏÒÓÖÙÚÜßàáäèéëìíïòóöùúü]*+" data-ng-model="user.companyname"> </div> <div class="form-group"> <label for="vorname">vorname*</label> <input type="text" data-ng-model="user.vorname" pattern="[a-za-z0-9ÀÁÄÈÉËÌÍÏÒÓÖÙÚÜßàáäèéëìíïòóöùúü]+" id="vorname" class="form-control" title="ihr vorname" required> </div> <div class="form-group"> <label for="nachname">nachname*</label> <input type="text" data-ng-model="user.nachname" id="nachname" pattern="[a-za-z0-9ÀÁÄÈÉËÌÍÏÒÓÖÙÚÜßàáäèéëìíïòóöùúü]+" title="ihr nachname" class="form-control" required> </div> <div class="form-group"> <label for="telefonnummer">telefonnummer</label> <input type="number" id="telefonnummer" data-ng-model="user.telefonnummer" max-length="14" min-length="11" width="100" class="form-control"> </div> <div class="form-group"> <label for="email">email*</label> <input type="email" id="email" data-ng-model="user.email" class="form-control" required novalidate> </div> </div> <div class="pull-right"> <div class="form-group text-area-group"> <label for="message">nachtricht</label> <textarea type="text" id="message" data-ng-model="user.message" rows="15" class="form-control" required></textarea> </div> </div> </div> <div class="form-group button-group text-center"> <button type="submit" id="send" class="btn btn-default">submit</button> </div> </form> </div>

the controller is:

.controller('simpleapp', ['$scope', function ($scope){ $scope.user = {}; $scope.sendemail = function (user) { $scope.userform.$setpristine(); //clear state $scope.user = {}; //empty form var telefon = 0; var message = 'no message'; console.log(user); if(user.telefonnummer != 'undefined') { telefon = user.telefonnummer; } if(user.message != 'undefined') { message = user.message; } var emailarray = { 'subject': 'contact request', 'companyname': user.companyname, 'vorname': user.vorname, 'nachname': user.nachname, 'telefonnummer': telefon, 'email': user.email, 'message': message, }; };

}]);

the problem is: works on plunker not application working on.

there scope related issue missing point. console gives errors $scope.userform undefined , $scope.user not available issue.

the problem right $setpristine() not work. if display error , user corrects it, go on sending previous state result in same error.

thank you.

angularjs

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -