Giter VIP home page Giter VIP logo

leocaseiro / angular-chosen Goto Github PK

View Code? Open in Web Editor NEW
682.0 54.0 248.0 1.11 MB

AngularJS Chosen directive is an AngularJS Directive that brings the Chosen jQuery in a AngularJS way

Home Page: http://leocaseiro.github.io/angular-chosen/

License: MIT License

CSS 1.75% CoffeeScript 21.81% HTML 16.47% JavaScript 59.97%
chosen select multiple angularjs-directives angularjs angular-chosen dropdown

angular-chosen's Issues

How would the spinner be useful when the select is to be populated conditionally

I was able to get the spinner to work but the undefined-checking makes it spin as soon as the page loads. In my case, the $resource.get doesn't fire until a condition is met. The spinner should start only at that moment.

I am working with the classic location selector, and its only the selection of country, that states are populated, and on selection of state, that cities are populated.

Any suggestions would be appreciated.

Chosen select do not show value in ng-model

Hi!
I have 2 chosen selects. One with parent and other with children values.I am populating parent model based on the model of child.Everything works fine as long as each parent has only one child.
But if parent contains multiple children and 2nd child of the certain parent is selected in the chosen select box,corresponding parent chosen select is not showing the model value.

These are my chosen select

This is my angular code for populating the umbrellas model according to fund model

if ($scope.childrenModel.length == 1) {
$scope.parentsModel.push($scope.someName);
}
When i am checking the value of $scope.parentsModel its showing correct value in it.But its still not getting displayed on chosen Select as selected option.

Error: 'undefined' is not an object (evaluating 'chosen.default_text') (only in mobile browsers)

I just got this error only when using iPhone/iPod touch.. You can see it when using Safari with iPhone selected as User-Agent

[Error] Error: 'undefined' is not an object (evaluating 'chosen.default_text')
initOrUpdate@http://..../angular-chosen-localytics/chosen.js:60:40
$render@http://..../angular-chosen-localytics/chosen.js:75:32
https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:189:12
$digest@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:109:81
$apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:112:180
h@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:72:306
w@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:77:446
onreadystatechange@https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js:78:376
    (anonyme Funktion) (angular.min.js, line 92)
    error (logging.js, line 38)
    $digest (angular.min.js, line 109)
    $apply (angular.min.js, line 112)
    h (angular.min.js, line 72)
    w (angular.min.js, line 77)
    onreadystatechange (angular.min.js, line 78)

When using ng-options on a single select after selecting an option attempting to select the last option will throw this error: "Uncaught TypeError: Cannot set property 'selected' of undefined"

It's an off by 1 error. ng-options is generating the list with n+1 options(the +1 being an empty option). The solution is to watch the select.length and on change throw an updated call.

Here is the fix, jam it in the linker function:

scope.$watch(function(){
    return element[0].length; 
}, function(newvalue, oldvalue){
    if (newvalue !== oldvalue) {
        element.trigger("chosen:updated");
    }
});

Bower install gives the wrong version

Like the title says; bower install angular-chosen-localytics` gives us the wrong version ( at least not the latest version ). Might want to push the new version of the plugin to bower.

Cheers.

ng-change on single deselect

I've been using ng-change on my chosen select box and it's been working quite well; however, the ng-change event doesn't get triggered when using the single deselect feature. Does this need to be implemented on the angular-chosen side?

Want to put angular-chosen inside my directive

HI,

When I try to move angular-chosen inside of my own directive html template I have some issues:

  • when construction is made within ng-hide chosen width is 0. (ng-if works fine)
  • ng-model field is not updated. (first time it is read fine)

Multiple Chosen Responsive: Width is Fixed

Besides I set the witdh:90% the directive convert to number XXXpx cause to multiple select not be responsive.

and the css is element.style { width: 294px; } .chosen-container { position: relative; display: inline-block; vertical-align: middle; font-size: 13px; zoom: 1; -webkit-user-select: none; -moz-user-select: none; user-select: none; }

angularjs: filtering with chosen control

Original jsfiddle with no filters, works as expected. http://jsfiddle.net/wKMZM/5/

Updated jsfiddle fails even to render the control. http://jsfiddle.net/wKMZM/3/

In the updated version, I have updated the ng-model to be associated with an array of objects. I have added a directive to convert it to an array of string in the filter directive.

Any idea, what I am missing?

Posted also on SO also: http://stackoverflow.com/questions/24909938/angularjs-filtering-with-chosen-control

Support ngDisabled

Hi,

angular-chosen doesn't work well with ngDisabled. I add the following codes:

          attr.$observe('disabled', function (value) {
            setTimeout(function() {
                element.attr('disabled', value).trigger("chosen:updated");
            });
          });

How do I get the selected element?

Sorry if this is not the place to ask this, but how do I get the chosen option that I am acting upon? For instance, if I have an option called "Item 1" and I click the "x" to remove it, I want to tell my ng-change event to make an ajax call to remove that item. Right now the model returns an array of items that remain selected, but not the one that was removed.

the select doesn't refill once the collection became empty

hi, i'm using ng-options together with chosen ... once my collection goes empty i get the message that there are no items. But if my collection has items again it doesn't add them, it stays empty. I'm using 1.1.5, so i'm not sure if it has anything to do with that or that there is a bug. Do you have an idea what this could be? Also the select element isn't updated either after it went empty ... if i remove the chosen directive from my select element, then it works.

<optgroup> Support?

Assuming that I have a collection of elements with a group property, is there a way to use 'ng-options' in such a way that it will produce correct '' tags? As I can't think of a way of doing this...

Default_text property error only in chrome

Hi
I get this error only in Chrome not in any other browser could any one point me in the right direction this is might be my own fault but the error msg could be better:

Chrome stacktrace:
TypeError: Cannot read property 'default_text' of undefined
at angular.module.directive.link.initOrUpdate (http://localhost:49904/Content/js/lib/chosen.js:59:40)
at angular.module.directive.link.ngModel.$render (http://localhost:49904/Content/js/lib/chosen.js:74:20)
at Object.ngModelWatch (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.11/angular.js:18352:14)
at Object.ng.config.$provide.decorator.$delegate.proto.$watch.watchExpression (:754:29)
at Scope.$get.Scope.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.11/angular.js:12443:40)
at Scope.ng.config.$provide.decorator.$delegate.proto.$digest (:844:31)
at Scope.$get.Scope.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.11/angular.js:12724:24)
at Scope.ng.config.$provide.decorator.$delegate.proto.$apply (:855:30)
at done (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.11/angular.js:8328:45)
at completeRequest (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.11/angular.js:8533:7)

Code:

$scope.load = function () {
$scope.konton = //fetch data
}

Html:

When i Debug Firefox never enter this method only Chrome and the chosen var get undefined:

    initOrUpdate = function() {
      if (chosen) {
        return element.trigger('chosen:updated');
      } else {
        chosen = element.chosen(options).data('chosen'); <-- this is undefined
        return defaultText = chosen.default_text;
      }

Cannot just pass any chosen attributes

Per readme here, allow-single-deselect is supported, and it used to be until 1.0.3. 1.0.4 regressed in that it no longer works.

I couldn't figure out from the commits, or else would have made a PR.

How to show default selected for single?

given the example : Changing the ngModel externally: {{ myPets }}

i removed 'multiple' from the selected and commented out
return $scope.myPets.push('hamster');
so to only have one selected item. i expected the select to default to 'cat' but it's still on 'Select an Option'. is this a bug? how can i get it to default to 'cat'?

chosen/select2 abstraction

It would be great to use this library with chosen or select2.

(I believed select2 was based on chosen but I didn't find any official confirmation).

I know there's already a angular-ui ui-select2 but I prefer this one :

  • $translate 2 support (translations with promises)
  • ngOptions support
  • ...

please add support of "ng-init" directive

example:

<select name="subject" ng-model="contactForm.subject" ng-init="contactForm.subject='value1'" required chosen disable-search="true" width="260">
      <option value="value1">test1</option>
      <option value="value2">test2</option>
      <option value="value3">test3</option>
</select>

with 'chosen' directive in hidden (original) select tag present bad option like this (before any changes):

<option value="? string:value1 ?"></option>

and I got javascript error if I checked last option in chosen select.

P.S. http://jsfiddle.net/darkfisk/UvzZf/
P.S. it seems to me that the initialization of the Chosen happens before the execution ng-init, which causes an error.

Focus show

How I can do that when it has focus display options?

No license

Without a license, people can't legally use this directive in their projects. Please consider adding one!

ng-model bug: Options shifted by one after selecting the first time

If you use the ng-model attribute, all the data-option-array-index attributes for li the elements under the chosen-results list are shifted by one (1, 2, 3... instead of 0, 1, 2...). Selection works the first time -- I'm guessing because the placeholder option is in the array and shifting all the other elements -- but every subsequent selection actually assigns the value after the selected value to the model (click on the second option, and the model is assigned the value for the third option). Picking the last value causes JQuery to throw an error.

How to reproduce:
Open angular-chosen/example/index.html
Pick a value from "Chosen with static options"
Pick another one and watch the model update to the value after it (or if the value selected is the last one, see JQuery throw an error in the console)

I'll try to see if I can fix it.

Google chrome emulate breaks angular-chosen plugin

I am using Chosen v1.1.0 with angular-chosen plugin on Google Chrome Version 33.0.1750.149. It works fine until I open browser console to emulate a mobile version and refresh the page. Is there a particular reason for this ?

README error

The module to be registered as a dependency is angular-chosen not localytics.directives.

Lexer error when trying to set no-results-text attribute to a string

When I try to set the html attribute "no-results-text" to a special character (like 'á' or 'é'), angular throws a lexer error since it tries to evaluate it as an expression at line 41:

return options[snakeCase(key)] = scope.$eval(value);

I could solve it by specifically filter this attribute separately but the issue should be addressed IMO

Empty list

For some reason the list isn't populated with my ng-options. If I use the select without the chosen directive I can see everything, but whenever I add the chosen directive the list is empty.

I'm using ajax loading.

jade:

select(chosen, ng-options='c._id as c.name for c in courses', ng-model='selectedCourse')

in the controller:

$scope.courses = Course.query();

Again, without the chosen directive the list is fine.

allow-single-deselect not compatible with angular filter

When using allow-single-deselect, the ng-model gets set to null by deselecting which is not compatible with angular filter.

I worked around by manually deleting the property

for k,v of factory.filter
      if !v
        delete factory.filter[k]

Disabled elements with empty option issues

I'm attempting to have a list of elements for my chosen field and disabled a few based on the disabled attribute of their object. This works great, however, when I switch between elements, the next value for ng-model is undefined. I read to add the empty option HTML element to the chosen element, however, upon doing so, my disabled options are offset by 1. Is there a way to have the proper values disabled while still swapping between ng-model values?

Thanks!

Failed to use

Chosen directive doesn't watch underlying model for changes

If the model is updated externally to this directive (ex. from a rest call) the directive doesn't update chosen. Something like

    require: 'ngModel',
        link: function(scope, element, attr, ctrl) {
            ctrl.$render = function () {
                $timeout(function() {element.trigger('chosen:updated');});
             };

should work.

Dynamic IDs in chosen generated HTML

Hello,
I have a question regarding dynamic IDs.
I'm generating many boxes and they get their ID by id="{{id}}". e.g. id="test" When chosen is applied to the select element, the ID of the chosen generated HTML is id="__test___chosen". Is there a way to get the ID to be id="test_chosen" by not setting it hardcoded in the HTML? I hope you understand my problem and might know an answer.

disable multiple

Hi,

there are some way to disable the control? I have tryed to put disabled in original select
but doesnt works

thanks

Don't scroll to top when selecting multiple items with ctrl

When selecting multiple items from a dropdown and holding ctrl, it would be more user friendly to prevent the default action to scroll to the top of the dropdown menu. I'm dealing with a dropdown of 200+ items and this is an annoying feature, to say at least.

Dynamic options

Hello!

I am having trouble with options mapped to a standard filter - the options stay in the chosen dropdown, just don't work while the model is changed. Is there a way to support this?

select(chosen, ng-model='data.item', ng-options='item.value as item.name for option in data.items | filter: search')

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.