Getting Started
How you acquire bootstrap-add-clear is up to you.Bower
Install with Bower:NPM
Install with NPM: If you are using browserify to bundle, you will have to expose jQuery globally: entry.jsGithub
Clone the boostrap-add-clear repository:Direct Download
Note: bootstrap-add-clear has a dependency on jquery 1.8+ and Bootstrap 3Available Options
Option | Type | Default | Description |
---|---|---|---|
closeSymbol | string | You can clear out the symbol class and instead use a character like '✖' | |
symbolClass | string | glyphicon glyphicon-remove-circle | The symbol class to assign to the floating div |
wrapperClass | string | This element wraps the entire input, you can assign a class to help with formatting | |
top | number | 0 | By default the symbol is centered, this numberof pixels can offset it up and down |
right | number | 0 | By default the symbol is centered, this number of pixels can offset it left and right |
returnFocus | boolean | true | If true, focus will return to the text box after clearing |
showOnLoad | boolean | false | If true, show the symbol when the script loads |
clearOnEscape | boolean | true | If true, clear the text box contents when the escape button is pressed |
hideOnBlur | boolean | false | If true, hide the symbol when focus is lost from the text box |
zindex | number | 100 | The zindex to apply to the symbol |
onClear | function | false | Function callback that runs when the text box is cleared. Clearing can occur from either clicking the symbol or pressing the escape key if clearOnEscape is set to true |
Examples
Default
bootstrap-add-clear will make a text box behave like this:
Example Code
Event Handler
The onClear event is triggered whenever the 'x' is clicked or the ESC button is pressed.
Example Code
Custom icon
It's easy to use other iconic fonts or images instead of glyphicons.