Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
By-passing $dirty check
Message
From
31/03/2015 03:23:49
 
General information
Forum:
Javascript
Category:
Other
Miscellaneous
Thread ID:
01609780
Message ID:
01617466
Views:
36
This message has been marked as a message which has helped to the initial question of the thread.
>Hi Viv,
>
>Somehow this doesn't seem to work on one page. I am getting a message about Changes.
>
>My directive is
>
>
>(function () {
>    'use strict';
>
>    var app = angular.module('sysMgrApp');
>
>    app.directive('noDirtyCheck', [function () {
>        // Interacting with input elements having this directive won't cause the
>        // form to be marked dirty.
>        // http://stackoverflow.com/questions/17089090/prevent-input-from-setting-form-dirty-angularjs
>        return {
>            restrict: 'A',
>           
>            require: 'ngModel',
>            link: function (scope, element, attrs, ctrl) {           
>
>                element[0].focus(function () {
>                    ctrl.$pristine = false;
>                });
>            }
>        };
>    }]);
>})();
>
>and the page has this control:
>
>
> <div class="col-lg-5 col-lg-offset-1">
>                    <input class="form-control" type="text" ng-model="searchTerm" data-no:dirty-check ="true"
>                    placeholder="@Labels.search" />
>                </div>
>
>when I type something in that control and inspect the element, I can see the ng-dirty class on it.
>
>Do you see why it's not working in that form? The directive does seem to work OK in other forms.

Surprised if it is. I think you need the $setPristine() *function* which doies:
 this.$setPristine = function() {
    ctrl.$dirty = false;
    ctrl.$pristine = true;
    $animate.removeClass($element, DIRTY_CLASS);
    $animate.addClass($element, PRISTINE_CLASS);
  };
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform