| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
UberSelect is a fancy UI on top of a regular <select> element.
Tested on jQuery 1.11.x to 3.3.x
UberSelect is composed of two main parts, an UberSearch that does all the of searching and UI, and an UberSelect which is used to connect an UberSearch to a <select> element.
This is the object that allows an UberSearch and a <select> element to work together. The select element can be used to control the state of the UberSearch, and vice-versa. This means you can programmatically change the state of the select, and UberSearch will update. Users can interact with the UberSearch, and the select will update. This also means you can use UberSelect to gussy up forms, without changing any of the underlying inputs.
$('.my_selects').uberSelect(options);Attributes on the outermost element can be specified by setting the data-uber-attributes attribute on the <select> element. Values should be passed as a JSON string of key/value pairs where the key is the attribute name and the value is the attribute value.
Options can be specified by setting the data-uber-options attribute on the <select> element. Values should be passed as a JSON string. All options on the are passed to the underlying UberSearch, see UberSearch options.
Determines whether the search input starts with the selected value in it when the pane is opened.
Default: false
Determines whether the select value should be cleared when the search is cleared.
Default: false
Placeholder to show in the selected text area.
Default: <select> element attributes <select placeholder="my placeholder" data-placeholder="my placeholder">
A url to pre-fetch select options from. JSON response should be of the form [{text:'option with explicit value', value: 'some value'}, {text:'option with implicit value'}]. For a custom JSON response, use in conjunction with optionFromDatum.
Default: null
A function that can modify the data from the dataUrl before it is used.
The function signature is as follows:
function(data) {
// Modify the data
return modifiedData
}See dataUrl for details about the expected format of data.
A function that is used to customize the option's value and text built from a JSON response. datum is a single result returned from the JSON response.
The function signature is as follows:
function(datum) {
return // a <option> element to represent the select
}Default: datum.value populates the <option> value, datum.text populates the <option> text.
Initialize the UberSearch with this selected value
Default: <select> element value property
Add an aria-label attribute with this value to the uber_select element.
<option> elements can each use data-attributes to control datum properties. See UberSearch data.
This fires when the UberSelect has initialized and is ready for user interaction
The <select> element observes the following events:
The UberSearch options list will be updated to match the <select> element's <option> list.
The UberSearch will update its selected value to match the <select> element's. This handler also runs when the <select> element triggers a change event.
The UberSearch performs all of the heavy lifting. It creates the UI views, maintains state, and performs the searching. It can be instantiated without the use of an UberSelect, which can be useful for situations where the selected value is being used in purely in JS, and not being linked to a <select> element in a form.
new UberSearch(data, options);Data is an array of objects. Each object may have the following properties:
String shown to the user in the list of results. This value is required if value is not provided.
String shown to the user in the output container when this option is selected. optional
Title text shown to the user when hovering over the result. optional
This is matched against the value option passed UberSearch and will appear selected if it matches. It is also used to match against search input text when the user searches. This value is required if text is not provided.
This overrides the value used to match against search input text when the user searches. optional
This is used to determine whether the option appears only when searching or only when not searching. Values accepted: query, no-query. optional
This is used to determine whether the option appears disabled. optional
This is used to visually group options. All options with the same group will appear together. optional
Sets the data. data should be an Array conforming to the specifications described in Data
Returns the currently selected value.
Returns the currently selected element from the search results.
Options can be specified by setting the data-uber-options attribute on the <select> element. Values should be passed as a JSON string.
Sets the initially selected value of the UberSearch. This value should match the value property of the desired option data.
Default: null
Determines whether the search input be shown.
Default: true
Sets the text content of clear search button.
Default: ✕
Sets the text content of clear select caret.
Default: ⌄
Sets whether blank options should be hidden automatically.
Default: false
Determines whether the text property of an option with a blank value property should be used as the placeholder text if no placeholder is specified.
Default: false
Determines whether the first search result be auto-highlighted.
Default: true
Sets minimum number of characters the user must type before a search will be performed.
Default: 0
Sets the message shown to the user when the query doesn't exceed the minimum length. true for a default message, false for none, or provide a string to set a custom message.
Default: true
Sets the placeholder shown in the selected text area.
Default: null
Sets the placeholder shown in the search input.
Default: 'Type to search'
Sets the message shown when there are no results.
Default: 'No Matches Found'
Sets the text to show when the results list is empty and no search is in progress
Default: 'No options'
An Object containing attributes to add to the search input element.
A function that is used to build result elements.
The function signature is as follows:
function(listOptionData) {
return // HTML/element to insert into the the results list
}A function that is run after a result is built and can be used to decorate it. This can be useful when extending the functionality of an existing UberSearch implementation.
The function signature is as follows:
function(resultsListElement, listOptionData) { }Default: No-op
A function to run when the results container is rendered. If the result returns false, the default render event handler is not run and the event is cancelled.
The function signature is as follows:
function(resultsContainer, searchResultsHTML) { }A function to run when a result is selected. If the result returns false, the default select event handler is not run and the event is cancelled.
The function signature is as follows:
function(listOptionData, resultsListElement, clickEvent) { }A function to run when a user presses enter without selecting a result. Should be used in combination with highlightByDefault: false.
The function signature is as follows:
function(value) { }Toggles whether or not to match results using their datum.group in addition to their datum.matchValue. When true the searches that match the group name will cause options within that group to appear.
Default: false
Toggles whether options page is always shown open. When true the pane will start open and will not close when an option is selected, when the Escape key is pressed, or when either the select itself or outside the select is clicked.
Default: false
An object that receives the output once a result is selected. Must respond to setValue(value) and view(). This object serves to attach the result list to the DOM at the desired location.
This fires when the UberSearch pane is opened.
This fires each time the list of results is updated.
This fires when the user clicks the clear search button.
This fires when the user selects a result.
The handler function signature is as follows:
function(event, [listOptionData, resultsContainer, originalEvent]) { }| Back | FazBrowse Home | New Git URL |