angular-chosen-localytics

WebJar for angular-chosen-localytics

License

License

MIT
Categories

Categories

Angular User Interface Web Frameworks
GroupId

GroupId

org.webjars.bower
ArtifactId

ArtifactId

angular-chosen-localytics
Last Version

Last Version

1.8.0
Release Date

Release Date

Type

Type

jar
Description

Description

angular-chosen-localytics
WebJar for angular-chosen-localytics
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/leocaseiro/angular-chosen

Download angular-chosen-localytics

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bower/angular-chosen-localytics/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>angular-chosen-localytics</artifactId>
    <version>1.8.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/angular-chosen-localytics/
implementation 'org.webjars.bower:angular-chosen-localytics:1.8.0'
// https://jarcasting.com/artifacts/org.webjars.bower/angular-chosen-localytics/
implementation ("org.webjars.bower:angular-chosen-localytics:1.8.0")
'org.webjars.bower:angular-chosen-localytics:jar:1.8.0'
<dependency org="org.webjars.bower" name="angular-chosen-localytics" rev="1.8.0">
  <artifact name="angular-chosen-localytics" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='angular-chosen-localytics', version='1.8.0')
)
libraryDependencies += "org.webjars.bower" % "angular-chosen-localytics" % "1.8.0"
[org.webjars.bower/angular-chosen-localytics "1.8.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.webjars.bower : jquery jar [2.0.3,3)
org.webjars.bower : chosen jar [1.5.1,2)
org.webjars.bower : angular jar [1.4.9,2)

Project Modules

There are no modules declared in this project.

Angular Chosen Localytics Bower npm

AngularJS Chosen directive

This directive brings the Chosen jQuery plugin into AngularJS with ngModel and ngOptions integration.

To use, include localytics.directives as a dependency in your Angular module. You can now use the chosen directive as an attribute on any select element. Angular version 1.3+ is required, but recommended 1.4.9+.

Full Documentation with Examples

Installation (npm or bower)

Via bower

$ bower install angular-chosen-localytics --save

Via npm

$ npm install angular-chosen-localytics --save

Via cdn

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chosen-localytics/1.9.2/angular-chosen.min.js"></script>

Or download zip file

Download v1.9.2

Yeoman or Bower install

If you use Yeoman or Bower install, you need to rename the chosen.jquery.js or the chosen.proto.js to chosen.js. Otherwise Chosen won't be included in your index.html.

Features

  • Works with ngModel and ngOptions
  • Supports usage of promises in ngOptions
  • Provides a 'loading' animation when 'ngOptions' collection is a promise backed by a remote source
  • Pass options to Chosen via attributes or by passing an object to the Chosen directive
  • Provider with default values with chosenProvider (read: Added config-provider) [since 1.6.0]

Usage

Simple example

Similar to $("#states").chosen()

<select chosen multiple id="states">
  <option value="AK">Alaska</option>
  <option value="AZ">Arizona</option>
  <option value="AR">Arkansas</option>
  <option value="CA">California</option>
</select>

Pass any chosen options as attributes

<select chosen
        data-placeholder-text-single="'Pick one of these'"
        disable-search="true"
        allow-single-deselect="true">
  <option value=""></option>
  <option>This is fun</option>
  <option>I like Chosen so much</option>
  <option>I also like bunny rabbits</option>
</select>

Note: the empty option element is mandatory when using allow-single-deselect

Integration with ngModel and ngOptions

<select multiple
        chosen
        ng-model="state"
        ng-options="s for s in states">
</select>

Note: don't try to use ngModel with ngRepeat. It won't work. Use ngOptions. It's better that way.

Also important: if your ngModel is null or undefined, you must manually include an empty option inside your <select>, otherwise you'll encounter strange off-by-one errors:

<select multiple
        chosen
        ng-model="state"
        ng-options="s for s in states">
  <option value=""></option>
</select>

This annoying behavior is alluded to in the examples in the documentation for ngOptions.

Works well with other AngularJS directives

<select chosen
        ng-model="state"
        ng-options="s for s in states"
        ng-disabled="editable">
  <option value=""></option>
</select>

Loading from a remote data source

Include chosen-spinner.css and spinner.gif to show an Ajax spinner icon while your data is loading. If the collection comes back empty, the directive will disable the element and show a default "No values available" message. You can customize this message by passing in noResultsText in your options.

app.js
angular.module('App', ['ngResource', 'localytics.directives'])
    .controller('BeerCtrl', function($scope, $resource) {
      $scope.beers = $resource('api/beers').query()
    });
index.html
<div ng-controller="BeerCtrl">
  <select chosen
          data-placeholder-text-single="'Choose a beer'"
          no-results-text="'Could not find any beers :('"
          ng-model="beer"
          ng-options="b for b in beers">
      <option value=""></option>
  </select>
</div>

Image of select defined above in loading state: <img src="https://raw.github.com/localytics/angular-chosen/master/example/choose-a-beer.png">

Note: Assigning promises directly to scope is now deprecated in Angular 1.2+. Assign the results of the promise to scope once the promise returns. The loader animation will still work as long as the collection expression evaluates to undefined while your data is loading!

Default values with chosenProvider (thanks @zlodes) [since 1.6.0]

angular.module('chosenExampleApp', ['localytics.directives'])
    .config(['chosenProvider', function (chosenProvider) {
        chosenProvider.setOption({
            no_results_text: 'There is no results!',
            placeholder_text_multiple: 'Choose one or more!'
        });
    }]);

Versions

Version
1.8.0
1.7.0
1.6.0
1.4.0
1.3.0