mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-19 14:06:33 +02:00
Assign item list values to hidden input value array
This commit is contained in:
parent
d0d8656ca8
commit
19c429bca8
2
assets/scripts/dist/bundle.js
vendored
2
assets/scripts/dist/bundle.js
vendored
File diff suppressed because one or more lines are too long
|
@ -128,12 +128,26 @@ import { wrap, getSiblings } from './lib/utils.js';
|
||||||
addItem(el, value) {
|
addItem(el, value) {
|
||||||
console.log('Add item');
|
console.log('Add item');
|
||||||
let wrapper = el.parentNode;
|
let wrapper = el.parentNode;
|
||||||
|
let valueInput = wrapper.querySelector('.choice__input--original');
|
||||||
|
|
||||||
let list = wrapper.querySelector('.choice__list');
|
let list = wrapper.querySelector('.choice__list');
|
||||||
|
|
||||||
let item = document.createElement('li');
|
let item = document.createElement('li');
|
||||||
item.classList.add('choice__item');
|
item.classList.add('choice__item');
|
||||||
item.textContent = value;
|
item.textContent = value;
|
||||||
|
|
||||||
|
if(valueInput.value === '') {
|
||||||
|
valueInput.value = JSON.stringify([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let valueInputArray = JSON.parse(valueInput.value);
|
||||||
|
|
||||||
|
valueInputArray.push(value);
|
||||||
|
|
||||||
|
valueInput.value = JSON.stringify(valueInputArray);
|
||||||
|
|
||||||
|
console.log(valueInput.value);
|
||||||
|
|
||||||
wrapper.appendChild(item);
|
wrapper.appendChild(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,6 +186,7 @@ import { wrap, getSiblings } from './lib/utils.js';
|
||||||
el.classList.add('choice__input', 'choice__input--original');
|
el.classList.add('choice__input', 'choice__input--original');
|
||||||
el.tabIndex = '-1';
|
el.tabIndex = '-1';
|
||||||
el.setAttribute('style', 'display:none;');
|
el.setAttribute('style', 'display:none;');
|
||||||
|
el.setAttribute('aria-hidden', 'true');
|
||||||
|
|
||||||
wrap(el, wrapper);
|
wrap(el, wrapper);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue