I'd like to change the placeholder-icon of a ionic-input element. Therfore I use a ng-show in two different icons. In the controller I compare two password-fields of equality. If they are equal, a checkmark is shown, if not a decline-icon is shown.
html:
<label class="item item-input">
<input type="password" name="newPasswordVerify" placeholder="retype new password" ng-model="user.newPasswordVerify"/>
<i ng-show="passCorrect" class="icon ion-ios7-close-empty placeholder-icon"></i>
<i ng-show="!passCorrect" class="icon ion-ios7-checkmark-empty placeholder-icon" ></i>
</label>
controller:
$scope.$watch('user.newPasswordVerify', function() {
if($scope.user.newPasswordVerify!=="")
{
if($scope.user.newPasswordVerify.equals($scope.user.newPassword))
$scope.passCorrect = true;
else
$scope.passCorrect = false;
}
});
I get a correct console-output, but the dom doesn't apply the changes.
Edit: fiddle
<form name="frm">
<label class="item item-input">
<input type="password" name="newPasswordVerify" placeholder="retype new password" ng-model="user.newPasswordVerify"/>
<i ng-show="passCorrect" class="icon ion-ios7-close-empty placeholder-icon"></i>
<i ng-show="!passCorrect" class="icon ion-ios7-checkmark-empty placeholder-icon" ></i>
</label>
</form>
When you give a <form>
tag a name Angular will assign it a FormController
to manage input validation. It's recommended to use that for validation because the life-cycle of model data can varry depending upon how you've setup the form. What's being shown on the page isn't always what is in the model data.
Each ngModel
directive will create a ngModelController
for that directive that allows you to add $validator
rules.
$scope.frm.newPasswordVerify.$validator.badPassword = function(modelValue,viewValue){
var value = modelValue || viewValue;
return $scope.user.newPassword == value;
};
The above will pass validation (true) if the two passwords match, otherwise it will fail. When it fails the CSS class ng-invalid-bad-password
will be assigned to the input. Likewise ng-valid-bad-password
when be assigned when true.
The form will have a $error
flag set to true for badPassword
to match validation.
<i ng-show="!frm.$error.badPassword" class="icon ion-ios7-close-empty placeholder-icon"></i>
<i ng-show="frm.$error.badPassword" class="icon ion-ios7-checkmark-empty placeholder-icon" ></i>
$scope.user.newPasswordVerify!==""
didn't work. I replaced it with
$scope.user.newPasswordVerify.charAt(0)
and it works