Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Breaking Change: ng-class is having issue with form.$pending #12188

Closed
niemyjski opened this issue Jun 22, 2015 · 13 comments
Closed

Breaking Change: ng-class is having issue with form.$pending #12188

niemyjski opened this issue Jun 22, 2015 · 13 comments

Comments

@niemyjski
Copy link

As you can see in my screenshot.. $pending isn't defined when I output the form via json.. Is anyone else seeing this?
image

The source for this can be found here: https://github.com/exceptionless/Exceptionless.UI/blob/master/src/app/organization/manage/manage.tpl.html#L14-L24

@Narretz
Copy link
Contributor

Narretz commented Jun 22, 2015

Please try to isolate the problem so you can put it in a plnkr or similar. Also, from what to which version were you updating when you encountered the problem?

@niemyjski
Copy link
Author

Yes, I'll work on putting together a sample. I wanted to at least log this as I was testing.

@niemyjski
Copy link
Author

I think the following jsfiddle demo will reproduce this issue.. However, I'm having issues getting it to run (I copy and pasted a second working example and that doesn't even work), for some reason my module is not being resolved... If you could help getting it to load I can investigate further..

https://jsfiddle.net/a5yrzep7/

@niemyjski
Copy link
Author

I've created a screencast of this issue as well comparing 1.3.x vs 1.4.x

http://screencast.com/t/GLDsnCRi345

niemyjski added a commit to exceptionless/Exceptionless.UI that referenced this issue Jun 29, 2015
@lgalfaso
Copy link
Contributor

I am not seeing the issue with Chrome 43 OSX. Is this browser specific?

@niemyjski
Copy link
Author

If you are looking at that jsfiddle.. I couldn't get it to work.. there was an error in the console saying couldn't load module.... So you can't use that to be a judge of it.. I've only tried chrome and edge.

@lgalfaso
Copy link
Contributor

I changed "Framework and Extension" to "No-Library (pure JS)" and everything worked. https://jsfiddle.net/s9gcnmhh/ What I cannot do is to reproduce the error

@niemyjski
Copy link
Author

Thanks, I'll try tracking this down more this week

@niemyjski
Copy link
Author

I've narrowed this down to my async validator..

    .directive('searchFilterValidator', ['$q', 'searchService', function($q, searchService) {
      return {
        restrict: 'A',
        require: 'ngModel',
        link: function(scope, element, attrs, ngModel) {
          ngModel.$asyncValidators.valid = function(query) {
            var deferred = $q.defer();

            if (ngModel.$pristine) {
                deferred.resolve(true);
            } else {
              searchService.validate(query).then(function(response) {
                if (!response.data.is_valid) {
                  deferred.reject(response.data.message);
                }
                deferred.resolve(true);
              });
            }

            return deferred.promise;
          };
        }
      };
    }]);

Seems to leave pending == true in some cases. However if I wrap it in a timeout it works every time.. Seems like some kind of a race condition.

    .directive('searchFilterValidator', ['$timeout', '$q', 'searchService', function($timeout, $q, searchService) {
      return {
        restrict: 'A',
        require: 'ngModel',
        link: function(scope, element, attrs, ngModel) {
          ngModel.$asyncValidators.valid = function(query) {
            var deferred = $q.defer();

            if (ngModel.$pristine) {
              $timeout(function () {
                console.log('pristine');
                deferred.resolve(true);
              }, 1);
            } else {
              searchService.validate(query).then(function(response) {
                if (!response.data.is_valid) {
                  deferred.reject(response.data.message);
                }
                deferred.resolve(true);
              });
            }

            return deferred.promise;
          };
        }
      };
    }]);

@Narretz
Copy link
Contributor

Narretz commented Aug 3, 2015

I still cannot reproduce the problem. Also, in your first post, you said that $pending is undefined, in your last post you say $pending stays true in some cases. So we'll still need a better repro.

@Narretz
Copy link
Contributor

Narretz commented Aug 15, 2015

Closing this until we have a better demo.

@Narretz Narretz closed this as completed Aug 15, 2015
@niemyjski
Copy link
Author

@Narretz Here is a plunk that I think reproduces the issue I was seeing.

http://plnkr.co/edit/PCNfs8HHBnqa9MgQ6ifx?p=preview

@niemyjski
Copy link
Author

Wait it's not the same bug because pristine is modified and it wasn't in my use case.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants