leocaseiro / angular-chosen

AngularJS Chosen directive is an AngularJS Directive that brings the Chosen jQuery in a AngularJS way
http://leocaseiro.github.io/angular-chosen/
MIT License
681 stars 248 forks source link

Chosen doesn't update when the model changes programmatically #244

Closed abyx closed 7 years ago

abyx commented 7 years ago

If you are going to be lazy asking me properly, I'll be lazy answering to you (@leocaseiro)

Please make sure you can mark all the options, before open this Issue. I'll prioritise the issues that are consistent and completed.

Please, post your plunker link here:

plunker

Write your issue:

As can be seen in the attached plunker, clicking the button, which updates the model value, does not result in chosen itself getting re-rendered. This seems to be because of this line in the code. At least when I'm looking at it, the .css() call always returns a value of 0px, even when the dropdown is closed, which prevents the updated event from getting triggered.

I have no problem creating a PR, but I'm just not sure what that line of code is trying to accomplish. Would it be enough to test whether the dropdown is open (e.g. by checking if the active class is applied)?

leocaseiro commented 7 years ago

Hi @abyx, thanks for pointing that out. I believe it's related to #243

I would appreciate a PR.

The fix was made in regards to the scrolling to top #59 and it was done in this commit https://github.com/leocaseiro/angular-chosen/commit/8b7e137f458f26fd643317cfa1102b7ccde5b238

I would need a better solution for fixing that issue. However, I see this issue and the #243 is a priority for most of the users.

VanTanev commented 7 years ago

My intuition is that we should remove the overwritten ngModel.render and the CSS hack and instead add something like:

ngModel.$formatters.push(function(value) {
  initOrUpdate()
  return value
})

The idea is that formatters are called only when angular changes the expression, while ngModelCtrl.render() is called both when angular chances it, and when chosen changes it

This is just a guess off the top of my head, haven't had the chance to think through it very deeply.

zlodes commented 7 years ago

Same :+1:

abyx commented 7 years ago

So, are you guys saying we should just ignore whatever that line was trying to fix? If so I'll send a PR.

leocaseiro commented 7 years ago

Hi @abyx, thanks for your keep up.

I would be very happy if the PR fixes the ngModel issue as well as keeping the chosen opened while holding the cmd on Mac or ctr on PC.

Thanks

abyx commented 7 years ago

Opened pull request #245 will appreciate feedback