# j-SearchBox

> The component contains a search box (input).

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: eb2f396bf24610791cca23beeb09618d8211c9d489face7c694c997b173b1493
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

The component contains a search box (input).


__Configuration__:

- `exec {String}` a link to the `function(model, component, changetype)`, it will be executed if the user presses enter
- `autocomplete {String}` a link to the `function(component, input)`, it will be executed if the user focuses the search box
- `init {String}` a link to the `function(component)`, it will be executed if the component is initialized
- `placeholder {String}` a placeholder for the search box
- `cleartype {Boolean}` clears type when the user will perform `ESC` (default: `false`)
- `keypress {Boolean}` key-press binding (default: `false`)
- `autotrim {Boolean}` trims the value automatically (default: `true`)
- `clicktype {String}` a link to the `function(component, currenttype, currentvalue)`, it will be executed if the user clicks on the `type` (a new `type` must be set via `component.type(html, value)`)

__Methods__:

- `component.type(html, id, [noemit])` adds a new type before the search input
- `component.enter()` performs searching manually
- __NEW__: `component.show()` focuses the input

Use it with `<ui-component name="searchbox">`. When the component is not loaded yet, jComponent downloads it on first use from the address in `DEF.fallback` (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

```html example.html
<ui-component name="menu"></ui-component>
<ui-component name="searchbox" config="exec:searchbox_enter;clicktype:searchbox_type;init:searchbox_init;placeholder:Search and press enter ..."></ui-component>

<script>
	function searchbox_enter(model, component) {

		// model.type
		// model.value

		alert(model.type + ': ' + model.value);
    }

    function searchbox_init(component) {
    	component.type('<i class="ti ti-user"></i> By name', 'name', true);
    }

    function searchbox_type(component) {
    	var opt = {};
		opt.items = [{ name: 'By name', value: 'name', icon: 'user' }, { name: 'By subject', value: 'subject', icon: 'text-width' }, { name: 'By body', value: 'body', icon: 'file-alt' }];
		opt.align = 'left';
		opt.element = component.element;
		opt.callback = function(selected) {
			component.type('<i class="ti ti-{0}"></i> {1}'.format(selected.icon, selected.name), selected.value, true);
		};
		SETTER('menu', 'show', opt);
    }

</script>
```
