Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
By-passing $dirty check
Message
De
01/04/2015 09:58:53
 
 
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01609780
Message ID:
01617609
Vues:
16
>>>>Why did you change from onblur to focus ?
>>>
>>>By investigating it a bit more I found that in the "working" form changing controls in the views that are supposed to trigger dirty state and don't have the no-dirty-check directive applied still don't make the form $dirty = true. So, it's a two-fold problem now.
>>
>>Not sure what you have wrong. Your binding syntax in the directive didn't work for me but this does:
element.bind('blur', function () {
>>ctrl.$setPristine();
>> scope.$apply();
>> })(scope.$apply() just there to update any validation markings)
>
>
>Thanks, Viv, I'll try that. I was also getting errors when I tried onblur.
>
>My problem is quite complex in that form. If I make a change in a page, then immediately try to switch to a different row from the parent form or go to another menu, I get a question about changes, so that's good. But if I make a change, switch to another tab in that form, then return to the same tab and try to go to another menu, I don't get the question and the dirty state of the form is lost.

>So, this is one problem with the technique we're using of switching tabs.

IIRC your tabs are replacing the view below them so the problem maybe that the view is being reloaded when you switch tabs. Did you try my suggestion to put named views *as tab content* ?

>
>However, it gets even more weird. If from the invoices list tab I go inside the invoice edit form, try to change search text (which has noDirtyCheck directive) on the Transactions page, then try to go to another tab within that invoice edit form, I get a prompt. I can answer that I don't care about changes, switch again, then back to transactions, then back to another tab and I again get the same prompt. In other words, in this particular case the dirty state remains and the form should not have been made dirty in the first place because I have this directive.

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.....

>So, that are my problems with that particular complex form. Yesterday I thought I'll try to fix the problem with Transactions page quickly and switch to a different task (calling C# static method from VFP). Instead I spent several hours in that form with 0 success. This is quite frustrating.... :(
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform