0

I have a SAVE button that is disabled when a form is pristine. I want it to say SAVED when pristine and then change to SAVE when the form is dirty. Working fine except the text change for the button. Here is the code:

     <input type="button" value="SAVED" class="button success radius expand" ng-click="save(form)" ng-disabled="!signupform.$dirty" ng-class="{disabled:!signupform.$dirty}">
3
  • What do you mean by pristine vs dirty? Commented Apr 10, 2015 at 3:09
  • 1
    The form is either pristine or dirty. Commented Apr 10, 2015 at 3:10
  • Why -1? $pristine and $dirty are valid angularjs properties. docs.angularjs.org/api/ng/type/form.FormController#$pristine Commented Apr 10, 2015 at 12:27

1 Answer 1

1

If you want to make inline just do:

<input type="button" value="{{(signupform.$dirty)? 'save' : 'saved'}}" class="button success radius expand" ng-click="save(form)" ng-disabled="!signupform.$dirty" ng-class="{disabled:!signupform.$dirty}">

You can also create a function in your controller to return the text. This can be useful if your logic is larger (different texts for various specific cases).

html

     <input type="button" value="{{getInputText()}}" class="button success radius expand" ng-click="save(form)" ng-disabled="!signupform.$dirty" ng-class="{disabled:!signupform.$dirty}">

controller:

function getInputText(form) {
    return (form.$dirty)? 'save' : 'saved';
}
Sign up to request clarification or add additional context in comments.

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.