Input Assistant
<msc-input-assistant /> is a web component which help user to input wisely. Users could search or pick option with list we provide. Once options are not good enough for them, they can 「add」 their own options for usage.
<msc-input-assistant /> will save options which user added in indexedDB. These options will be available in the same domain.
Let's check what can <msc-input-assistant /> do ?
Basic
Combined with <input />
Basic Usage
<msc-input-assistant /> is a web component. All we need to do is put the required script into your HTML document. Then follow <msc-input-assistant />'s html structure and everything will be all set.
Required Script
Structure
Put <msc-input-assistant /> into HTML document. It will have different functions and looks with attribute mutation.
Otherwise, developers could also choose remoteconfig to fetch config for <msc-input-assistant />.
JavaScript Instantiation
<msc-input-assistant /> could also use JavaScript to create DOM element. Here comes some examples.
Style Customization
Developers could apply styles to decorate <msc-input-assistant />'s looking.
Attributes
<msc-input-assistant /> supports some attributes to let it become more convenience & useful.
module
Set module for <msc-input-assistant />. <msc-input-assistant /> will apply this valus as key for data storage (indexedDB). Default is assistant (not set).
options
Set options for <msc-input-assistant />. It should be JSON string. Developers could set defalt options. Default is [] (not set).
forceupdate
Set forceupdate for <msc-input-assistant />. It will decide append data or just remain current options' data. Default is false (not set).
l10n
Set localization for <msc-input-assittant />. It will replace some message & button text to anything you like. It should be JSON string. Developers could set back、search、submit、inputLabel and inputPlaceholder.
- back:back to pick mode text. Default is Back.
- search:search field's placeholder. Default is search.
- submit:button 「SUBMIT」text. Default is SUBMIT.
- inputLabel:Add Mode > input field's label. Default is Add option.
- inputPlaceholder:Add Mode > input field's placeholder. Default is add option please.
Properties
| Property Name | Type | Description |
|---|---|---|
module
|
String | Getter / Setter for current storage key. Default is assistant (not set). |
options
|
Array | Getter / Setter for options. Default is [] (not set). |
forceupdate
|
Boolean | Getter / Setter for data writing mode. It will decide append data or just remain current options' data. Default is false (not set). |
l10n
|
Object | Getter / Setter for l10n. It will replace some message & button text to anything you like. Developers could set back、search、submit、inputLabel and inputPlaceholder. |
results
|
Array | Getter for current display options. |
Methods
| Method Signature | Description |
|---|---|
clearStorage
|
Clear current storage data (by current module). This is an async method. |
add(option)
|
Add option. This is an async method and makes UI mutated. |
query(keyword)
|
Query options by keyword and return results. This is an async method and makes UI mutated. |
Events
| Event Signature | Description |
|---|---|
msc-input-assistant-pick
|
Fired when option picked. |
msc-input-assistant-add
|
Fired when option added. |
msc-input-assistant-delete
|
Fired when option deleted. |