I need to reset the text from 3 input fields to empty after a click on a button. When i click on the button "Speichern" the text stays in the input field but I want that these input fields are empty after the click.
<div class="cInputChangePWColor">
<div class="cClearFloat cInputSpace">
<input class="cInputWidth" placeholder="Altes Passwort" ng-model="passwordOld">
</div>
<div class="cClearFloat cInputSpace">
<input class="cInputWidth" placeholder="Neues Passwort" ng-model="passwordNew">
</div>
<div class="cClearFloat cInputSpace">
<input class="cInputWidth" placeholder="Passwort bestätigen" ng-model="passwordNewConfirmed">
</div>
<div class="cClearFloat cButtonPosition">
<button class="cButtonSpeichernSettings" ng-click="showAlertchangePassword(); setTextDefault()">Speichern</button>
<button class="cButtonAbbrechenSettings" ng-click="isShownchangePw = false; isShownSettings = false">Abbrechen</button>
</div>
</div>
I tried it like this but it's not working.
$scope.setTextDefault = function() {
$scope.passwordOld == '';
$scope.passwordNew == '';
$scope.passwordNewConfirmed == '';
}
Change $scope.passwordOld == '';
to $scope.passwordOld = '';
$scope.reset = function(form) {
var fields = Object.keys(form).filter(function(key) {
return (key.indexOf('$') !== 0);
});
for (var i = 0; i < fields.length; i++) {
var name = fields[i];
var field = form[name];
field.$setViewValue(undefined);
field.$render();
}
form.$setPristine();
form.$setUntouched();
};
You can also use the reset function. You just need to wrap the DOM in a Form
and pass the $scope.formName
to reset function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.