Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

Hi I have a form with some inputs like email, title, color...

I have 2 buttons "Save" and "Undo changes".

I need that this buttons will be always disabled accept, if something was changed. For example I started to change email and then I considered. While I'm typing new email buttons should be enabled, but after click on one of them they should be disabled again.

<form name="form" ng-submit="change()" novalidate>
    <input type="text" ng-model="title"/>
    <input type="email" name="email" ng-model="email" placeholder="{{email}}" />
    <input type="color" ng-model="color"/>

    <button type="submit" ng-disabled="!form.$dirty">SAVE</button>
    <a ng-click="cancel()" ng-disabled="!form.$dirty">UNDO CHANGES</a>
</form>

How can I make them disable again after click on one of buttons?

share|improve this question
up vote 0 down vote accepted

Call $scope.form.$setPristine() to cancel all the dirty flags:

function TodoCtrl($scope) {

    $scope.change = function() {
        $scope.form.$setPristine();
    }

    $scope.cancel = function() {
        $scope.form.$setPristine();
    }
}

Example: http://jsfiddle.net/ej5et0f5/1/

share|improve this answer

Simply create a flag variable that you'll set to true after submitting and to false after changing inputs, then just do:

<button type="submit" ng-disabled="flagVariable">
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.