I have a text input field for address, whenever the address is entered and search button next to the input field is clicked, I geocode the address and replace the input text with the result from the geocoder. I also set a scope variable 'addressOk'.
is it possible to invalidate this specific form input field according to $scope.addressOk
or do I have to write a directive for this address geocoding input that invalidates the form when needed ?
The form instance can optionally be published into the scope using the name attribute. So to check form validity, you can check value of $scope. yourformname. $valid property of scope.
resetForm = function(){ /* reset the data to a new object so that all the properties * of form are reset */ $scope. data = {}; }; });
1) To Remove the values in Form Fields and to reset you can use $setPristine(); $scope. formName. $setPristine();
ng-controller directive tells AngularJS what controller to use with this view. AngularJS application mainly relies on controllers to control the flow of data in the application.
I found the solution, add a name attribute to the <form>
and <input>
, and then in the controller its possible to do $scope.formName.inputName.$setValidity(errorKey, isValid)
.
Then, its possible to display errors with something like ng-show="formName.inputName.$error.errorkey"
according to http://docs.angularjs.org/api/ng.directive:form If name attribute is specified, the form controller is published onto the current scope under this name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With