0

I have 3 fields like password, new password and confirm new password, and Submit button.

Now i want to perform 2 functions :

  1. When existing password is written SUBMIT button should activate.
  2. When new password is written the submit button should get deactivated and gets activated only when the confirm new password is entered

Here is my code :

<div ng-show="normalSignIn">
    <div class="row" ng-class="{ 'has-error' : accountDetailsForm.exispassword.$invalid && !accountDetailsForm.exispassword.$pristine }">
        <div class="col">
            <div class="input-label">Existing Password*</div>
            <input type="password" class="edit-password" placeholder="Please enter" ng-model="signinInfo.password" name="exispassword" ng-minlength="8" ng-readonly="isReadOnly"
                ng-required="normalSignIn" >
            <p ng-show="accountDetailsForm.exispassword.$error.minlength && !accountDetailsForm.exispassword.$pristine" class="help-block">Password must be 8 character
                long.</p>
            <p ng-show="accountDetailsForm.exispassword.$error.required && !accountDetailsForm.exispassword.$pristine" class="help-block">Please enter a password.</p>
        </div>
    </div>
    <div class="row" ng-class="{ 'has-error' : accountDetailsForm.password.$invalid && !accountDetailsForm.password.$pristine }">
        <div class="col">
            <div class="input-label">New Password</div>
            <input type="password" class="edit-password" placeholder="Please enter" ng-model="accountDetails.password" name="password" ng-minlength="8" ng-readonly="isReadOnly" ng-dirty="true">
            <p ng-show="accountDetailsForm.password.$error.minlength && !accountDetailsForm.password.$pristine" class="help-block">Password must be 8 character long.</p>

        </div>
    </div>
    <div class="row" ng-class="{ 'has-error' : accountDetailsForm.confirmPassword.$invalid && !accountDetailsForm.confirmPassword.$pristine }">
        <div class="col">
            <div class="input-label">Confirm New Password</div>
            <input type="password" class="edit-password" placeholder="Please enter" ng-model="confirmPassword" name="confirmPassword" match="accountDetails.password"
                ng-readonly="isReadOnly">
            <p ng-show="accountDetailsForm.confirmPassword.$error.match && !accountDetailsForm.confirmPassword.$pristine" class="help-block">Confirm and New password should
                be same.</p>
        </div>
    </div>
</div>

<div class="col">
        <button class="button button-block button-rentr-primary" ng-hide="hideTapToEdit" ng-click="landlordDetailCtrl.updateAccountDetails(signinInfo,accountDetails)"
            ng-disabled="accountDetailsForm.$invalid">SAVE</button>
    </div>

Any one have idea please let me know.?

2 Answers 2

1

If i understand correctly, you want the submit button to be disabled only when the user changed the form towards an invalid state - and not right from the start.

This can be done with the $dirty flag, which specifies if the control has been changed by the user. You could try changing the ng-disabled of your submit button to the following:

accountDetailsForm.exispassword.$dirty &&
accountDetailsForm.password.$dirty && 
accountDetailsForm.$invalid

PS: There is also $touched, which is very similar to $dirty. For the fine difference see the docs.

Sign up to request clarification or add additional context in comments.

1 Comment

it should be disabled at start
0

You can try this -

 ng-disabled="!(signinInfo.password || (accountDetails.password && confirmPassword))"

So your button code will be -

    <button class="button button-block button-rentr-primary"
            ng-hide="hideTapToEdit"
            ng-click="landlordDetailCtrl.updateAccountDetails(signinInfo,accountDetails)"
            ng-disabled="!(signinInfo.password || (accountDetails.password && confirmPassword))">
           SAVE
    </button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.