Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
By-passing $dirty check
Message
 
 
À
31/03/2015 03:23:49
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01609780
Message ID:
01617476
Vues:
23
>>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);
>  };
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).
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform