pSelect
Fancy dropdown select widget built using angular.js.
Supports Ajax search or just use it to pretty up your
regular <select> widget.
Ajax Search
(Using tvguide.com's search API; hope they don't mind)
Basic Multiple-Choice Ajax Search Widget
Code
Explanation of Attributes
multiple
Makes it a multiple-select widget
name="tvshows"
Form field name (required)
ajax-url="http://mapi.tvguide.com/watchlist/search"
URL for the search API
search-key="keyword"
Indicates query parameter expected by the API. This one expects 'keyword', e.g.
?keyword=modern+family
Defaults to 'q', so if your query looks like q=the+simpsons, you can skip this.
extra-search-params="{'limit':'10', 'v': '1.0'}"
Additional parameters to pass to the API. Optional
value-field="id"
The field in the returned data to use as the form value. This API returns items with a structure
like
{'name': 'The Simpsons', 'id': '100521', ...}
so we use "id" as the value field (and "name"
in the display-field see below).
display-field="name"
The field in the returned data to display in the dropdown
placeholder="Find TV Shows or Movies"
Placeholder text (optional, defaults to "Select")
ng-model="tc.showsAndMovies"
The model corresponding to the field. Required
Alternate Template
This is probably the most useful thing about the widget.
You can completely customize the dropdown and results by
editing the HTML template.
This version displays images (when available) with each choice.
Additional Attributes
template-url="html_templates/picture_template.html"
Specifies html template for displaying the widget. Default is
p_select.html
Single-Selection Version
Same as the first one, but leave off the multiple attribute
Preselected Options on an Ajax Widget
The Simpsons
Futurama
Code
Same as above, but encloses a <select> tag with preselected options:
Also notice that 'name' and 'multiple' attributes can be set on the <select> tag.
The idea is that you can just enclose an existing <select> and it will work the
way you expect
Prettification of Standard Non-Ajax Select Widget
Enclose a standard <select> with the directive.
Bob Hope
Bob Newhart
Bob Dobbs
Bob the Builder
Bob Marley
Bob Melvin
Bob Dylan
Code
Multiple Choice, with Preselected Options.
Bob Hope
Bob Newhart
Bob Dobbs
Bob the Builder
Bob Marley
Bob Melvin
Bob Dylan