Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
By-passing $dirty check
Message
De
01/04/2015 11:18:16
 
 
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01609780
Message ID:
01617623
Vues:
18
>>>>Bear in mind that simply setting an inputs $dirty to false (even when there are no other dirty controls) will not cause the form $dirty to be re-evaluated. You may need something like this in your directive after $setPristine():
var dirty = false;
>>>>angular.forEach(scope.theForm, function (value, key) {
>>>>    if (key[0] != '$') {
>>>>        if (value.$dirty) {
>>>>                dirty = true;
>>>>        }
>>>>    }
>>>>});
>>>>if (!dirty) {
>>>>scope.theForm.$setPristine();
>>>>}
This will reset the form if all inputs are pristine.....
>>>>
>>>
>>>For this code to work do I need to add
>>>
>>>require: ['^form'],
>>>
>>>and use scope.form syntax where you used scope.theForm
>>>
>>>?
>>'theForm' needs to be the name you have given to the angular form containing the inputs - I'm afraid that doesn't make the directive very portable.
>>
>>Maybe there's a better way of identifying the FormController that doesn't rely on the name......
>
>For now I tried without that addition with a very slight change:
>
>
>element[0].bind('blur', function () {
>                    ctrl.$setPristine();
>                    scope.$apply();
>                })
>
>e.g. I used element[0] instead of just element. But I am getting this error
>
>TypeError: undefined is not a function
>
>I can remove [0] if that's the source of the error. What do you think?

Remove it...
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform