question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting angular-chosen directive ng-model attribute from a controller function, angular-chosen does not update it.

See original GitHub issue

Hello Leo, angular-chosen directive is a time saving piece of code, obrigado thanks.

I’ve run into an issue when moving from v1.3.0 to v1.5.0;

Setting chosen directive ng-model attribute from a ctlr function, angular-chosen does not update it.

because initOrUpdatefunction returns before it reaches element.trigger('chosen:updated'). After some inspection, commenting the return statement, made it work.

if (dropListDom && dropListDom.length > 0 && dropListDom.css("left").indexOf("0") >= 0)
       { //return; /*commented to test*/}
 return element.trigger('chosen:updated');

However, console.log shows me both approaches (via chosen or via function) enters the condition, so the root cause it’s not the return statement. The fact is that via function, the dropListDom.css do not receive de .ng-valid-parse class. Maybe this is the reason, but my skills cannot ensure that. And also I don’t know why, when using the fn, the directive updates twice.

Thank you, valeu! -egidio

image

image

chosen 1.6.2 / angular-chosen v1.5.0

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:26 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
thelastinuitcommented, Oct 18, 2016

What works for me was: NOTE: I tried a custom selected variable, nop, it does not work but the convention is all right.

$scope.object = {
   selected: [0]
}
$scope.objects = [
{
  id: 1
  name: "Han Solo"
},
{ ... }
]

and in the view

<select 
  chosen 
  multiple
  data-placeholder="Select one or few star wars heroes"
  ng-model="object.selected"                                                                                                                                                       
  ng-options="o.id as o.name for o in objects">
  <option value=""></option>
</select>

and it works quite great! @leocaseiro thanks, carnal!!!

1reaction
leocaseirocommented, Nov 2, 2016

Just an update that any better fix to avoid the scroll go to the top will be accepted as a PR.

PS: I’m also planning to implement a kind of emit call for chosen:update. Probably will work on that this weekend. (If I have time to do so).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ng-model does not update controller value - Stack Overflow
As a rule of thumb, you should have a dot in an expression provided to the ng-model directive (for example, ng-model="thing.name"). Scopes are...
Read more >
Angular Chosen
This directive brings the Chosen jQuery plugin into AngularJS with ngModel and ngOptions integration. Angular version 1.2+ is required. WARNING: Since the ...
Read more >
AngularJS + Chosen Plugin = Awesome - One Hungry Mind
This is a screencast that shows how to integrate the awesome Chosen plugin into AngularJS. Chosen is one of my new favorite jQuery...
Read more >
Angular Directive For jQuery Chosen Plugin - Morioh
Angular Chosen Localytics This directive brings the Chosen jQuery plugin into ... ngModel is null or undefined, you must manually include an empty...
Read more >
Angular Chosen Isn'T Working Properly - ADocLib
CSDNSetting angularchosen directive ngmodel attribute from a controller function angularchosen does not update it. Angular uses twoway data binding and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found