Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
By-passing $dirty check
Message
De
31/03/2015 08:28:06
 
 
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01609780
Message ID:
01617477
Vues:
20
J'aime (1)
>>>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) {           
>>>
>>>             >>>            }
>>>        };
>>>    }]);
>>>})();
>>>
>>>and the page has this control: element[0].focus(function () {
>>> ctrl.$pristine = false;
>>> });

>>>
>>>
>>> <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);
>>  };
>
>I may try this one as a separate directive. Should it be called from onblur? But yet indeed that directive works fine in other forms (and this is based on that link you pointed me to).

I would think onblur is the right event. Try just changing to:
element[0].focus(function () {
                   ctrl.$setPristine();
               });
(Haven't tried it)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform