2021-01-29 00:20:46 +05:30
---
stage: none
group: unassigned
2021-02-22 17:27:13 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2021-01-29 00:20:46 +05:30
---
2017-08-17 22:00:37 +05:30
2021-01-29 00:20:46 +05:30
# InputSetter plugin
`InputSetter` is a DropLab plugin that allows for updating DOM out of the scope
of DropLab when a list item is clicked.
2017-08-17 22:00:37 +05:30
## Usage
2021-01-29 00:20:46 +05:30
Add the `InputSetter` object to the plugins array of a `DropLab.prototype.init`
or `DropLab.prototype.addHook` call.
2017-08-17 22:00:37 +05:30
2021-01-29 00:20:46 +05:30
- `InputSetter` : Requires a configuration value for `input` and `valueAttribute` .
- `input` : The DOM element that you want to manipulate.
- `valueAttribute` : A string that's the name of an attribute on your list items
that's used to get the value to update the `input` element with.
2017-08-17 22:00:37 +05:30
2021-01-29 00:20:46 +05:30
You can also set the `InputSetter` configuration to an array of objects, which
allows you to update multiple elements.
2017-08-17 22:00:37 +05:30
```html
< input id = "input" value = "" >
< div id = "div" data-selected-id = "" > < / div >
< input href = "#" id = "trigger" data-dropdown-trigger = "#list" >
< ul id = "list" data-dropdown data-dynamic >
< li > < a href = "#" data-id = "{{id}}" > {{text}}< / a > < / li >
< ul >
```
2019-09-30 21:07:59 +05:30
2020-05-24 23:13:21 +05:30
```javascript
2019-09-30 21:07:59 +05:30
const droplab = new DropLab();
const trigger = document.getElementById('trigger');
const list = document.getElementById('list');
const input = document.getElementById('input');
const div = document.getElementById('div');
droplab.init(trigger, list, [InputSetter], {
InputSetter: [{
input: input,
valueAttribute: 'data-id',
} {
input: div,
valueAttribute: 'data-id',
inputAttribute: 'data-selected-id',
}],
});
droplab.addData('trigger', [{
id: 0,
text: 'Jacob',
}, {
id: 1,
text: 'Jeff',
}]);
2017-08-17 22:00:37 +05:30
```
2021-01-29 00:20:46 +05:30
In the previous code, if the second list item was clicked, it would update the
`#input` element to have a `value` of `1` , it would also update the `#div`
element's `data-selected-id` to `1` .
2017-08-17 22:00:37 +05:30
2021-01-29 00:20:46 +05:30
Optionally, you can set `inputAttribute` to a string that's the name of an
attribute on your `input` element that you want to update. If you don't provide
2021-02-22 17:27:13 +05:30
an `inputAttribute` , `InputSetter` updates the `value` of the `input`
2021-01-29 00:20:46 +05:30
element if it's an `INPUT` element, or the `textContent` of the `input` element
if it isn't an `INPUT` element.