MrSolution MrSolution - 5 months ago 6
AngularJS Question

How can I check if the text of an input field is "yes"or "no"?

I want to check if the text from an input field is "yes" or "no". Is it possible to do this with

ng-click
?

<div class="cClearFloat cInputSpace">
<input placeholder="login" ng-model="currentUser.login">
</div>
<div class="cClearFloat cInputSpace">
<input placeholder="Vorname" ng-model="currentUser.Vorname">
</div>
<div class="cClearFloat cInputSpace">
<input placeholder="Nachname" ng-model="currentUser.Nachname">
</div>
<div class="cClearFloat cInputSpace">
<input placeholder="password" ng-model="currentUser.password">
</div>
<div class="cClearFloat cInputSpace">
<input placeholder="Admin" ng-model="currentUser.isAdmin">
</div>
<div class="cClearFloat cButtonsUser">
<button class="cButtonSpeichern" ng-click="saveUser()">Speichern</button>
<button class="cButtonAbbrechen" ng-click="isShownUser= false">Abbrechen</button>
</div>
</div>


These are the input fields and when I press on the button "Speichern", I want to check it.

Answer

What is the problem to check your inputs on ng-click handler?

if ($scope.currentUser.login && $scope.currentUser.login.toLowerCase() ==='yes') {
console.log('that is it');
}

UPDATED:

If you have time, Ill advice you to read about ng-model controller. Filds validation is his responosibility and it have a lot of tools for this.

Comments