|
|
|
@ -7,7 +7,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
<div class="field-text field-select__selections" onclick={ (event) => { handleToggleSelection(event) } }>
|
|
|
|
<div class="field-text field-select__selections" onclick={ (event) => { handleToggleSelection(event) } }>
|
|
|
|
<ul class="field-select__selections-list">
|
|
|
|
<ul class="field-select__selections-list">
|
|
|
|
<li class="badge badge--success field-select__selections-item" each={ item in state.selected } onclick={ (event) => { handleToggle(event, item) } }>
|
|
|
|
<li class="badge badge--success field-select__selections-item" each={ item in state.selected } onclick={ (event) => { handleToggle(event, item, 'selected') } }>
|
|
|
|
{ item[ state.keys.label ] }
|
|
|
|
{ item[ state.keys.label ] }
|
|
|
|
<button type="button" class="field-select__selections-remove">
|
|
|
|
<button type="button" class="field-select__selections-remove">
|
|
|
|
⮾
|
|
|
|
⮾
|
|
|
|
@ -24,18 +24,18 @@
|
|
|
|
<div class="panel">
|
|
|
|
<div class="panel">
|
|
|
|
<div class="bar justify-content-end">
|
|
|
|
<div class="bar justify-content-end">
|
|
|
|
<div class="bar__start">
|
|
|
|
<div class="bar__start">
|
|
|
|
{ state.selected.length } / { state.options.length } 🗇
|
|
|
|
{ state.preSelected.length } / { state.options.length } 🗇
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="{ getFilterClasses(['field-select__options-filter']) }" if={ props.searchable !== undefined }>
|
|
|
|
<div class="{ getFilterClasses(['field-select__options-filter']) }" if={ props.searchable !== undefined }>
|
|
|
|
<input type="text" class="field-text m-top-0" placeholder={ props.placeholderFilter } onkeyup={ (event) => { handleOnKeyUp(event) }} disabled={ props.disabled !== undefined } />
|
|
|
|
<input type="text" class="field-text m-top-0" placeholder={ props.placeholderFilter } paste={ (event) => { handleOnKeyUp(event) }} onkeyup={ (event) => { handleOnKeyUp(event) }} disabled={ props.disabled !== undefined } />
|
|
|
|
<button type="button" class="field-select__options-filter-reset" onclick={ (event) => { handleResetSearchable(event) } }>
|
|
|
|
<button type="button" class="field-select__options-filter-reset" onclick={ (event) => { handleResetSearchable(event) } }>
|
|
|
|
⮾
|
|
|
|
⮾
|
|
|
|
</button>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="field-select__options-panel">
|
|
|
|
<div class="field-select__options-panel">
|
|
|
|
<ul class="field-select__options-list">
|
|
|
|
<ul class="field-select__options-list">
|
|
|
|
<li class="{ getItemClasses(['field-select__options-item'], option) }" each={ option in state.options } onclick={ (event) => { handleToggle(event, option) } }>
|
|
|
|
<li class="{ getItemClasses(['field-select__options-item'], option) }" each={ option in state.options } onclick={ (event) => { handleToggle(event, option, 'preSelected') } }>
|
|
|
|
<span class="field-select__options-item-check">
|
|
|
|
<span class="field-select__options-item-check">
|
|
|
|
☑
|
|
|
|
☑
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
@ -50,6 +50,9 @@
|
|
|
|
</ul>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="display-flex">
|
|
|
|
<div class="display-flex">
|
|
|
|
|
|
|
|
<button type="button" class="button button--danger button--full m-bottom-0 w-100" onclick={ (event) => { handleOptionsCancel(event) } }>
|
|
|
|
|
|
|
|
🗙
|
|
|
|
|
|
|
|
</button>
|
|
|
|
<button type="button" class="button button--success button--full m-bottom-0 w-100" onclick={ (event) => { handleOptionsConfirm(event) } }>
|
|
|
|
<button type="button" class="button button--success button--full m-bottom-0 w-100" onclick={ (event) => { handleOptionsConfirm(event) } }>
|
|
|
|
✓
|
|
|
|
✓
|
|
|
|
</button>
|
|
|
|
</button>
|
|
|
|
@ -76,6 +79,7 @@
|
|
|
|
value: 'value'
|
|
|
|
value: 'value'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
selected: [],
|
|
|
|
selected: [],
|
|
|
|
|
|
|
|
preSelected: [],
|
|
|
|
hasUpdated: false,
|
|
|
|
hasUpdated: false,
|
|
|
|
options: [],
|
|
|
|
options: [],
|
|
|
|
query: '',
|
|
|
|
query: '',
|
|
|
|
@ -158,7 +162,20 @@
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* adding preSelected to selected, close modal
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
handleOptionsConfirm(event) {
|
|
|
|
handleOptionsConfirm(event) {
|
|
|
|
|
|
|
|
this.state.selected = JSON.parse(JSON.stringify(this.state.preSelected))
|
|
|
|
|
|
|
|
this.handleToggleSelection(event)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* close modal
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
handleOptionsCancel(event) {
|
|
|
|
this.handleToggleSelection(event)
|
|
|
|
this.handleToggleSelection(event)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
@ -177,6 +194,7 @@
|
|
|
|
this.state.isSelectionOpen = false
|
|
|
|
this.state.isSelectionOpen = false
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
this.state.isSelectionOpen = true
|
|
|
|
this.state.isSelectionOpen = true
|
|
|
|
|
|
|
|
this.state.preSelected = JSON.parse(JSON.stringify(this.state.selected))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.update()
|
|
|
|
this.update()
|
|
|
|
@ -205,7 +223,7 @@
|
|
|
|
* toggle selected, if not found add to selected
|
|
|
|
* toggle selected, if not found add to selected
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
handleToggle(event, option) {
|
|
|
|
handleToggle(event, option, key) {
|
|
|
|
|
|
|
|
|
|
|
|
event.stopPropagation()
|
|
|
|
event.stopPropagation()
|
|
|
|
|
|
|
|
|
|
|
|
@ -214,16 +232,16 @@
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const index = this.searchSelected(option)
|
|
|
|
const index = this.search(option, this.state[key])
|
|
|
|
|
|
|
|
|
|
|
|
if (index !== false) {
|
|
|
|
if (index !== false) {
|
|
|
|
this.state.selected.splice(index, 1)
|
|
|
|
this.state[key].splice(index, 1)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if ((this.props.multiple === undefined && this.state.selected.length > 0)) {
|
|
|
|
if ((this.props.multiple === undefined && this.state[key].length > 0)) {
|
|
|
|
this.state.selected = []
|
|
|
|
this.state[key] = []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.state.selected.push(option)
|
|
|
|
this.state[key].push(option)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.update()
|
|
|
|
this.update()
|
|
|
|
@ -246,7 +264,7 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getItemClasses(classes, option) {
|
|
|
|
getItemClasses(classes, option) {
|
|
|
|
const index = this.searchSelected(option)
|
|
|
|
const index = this.search(option, this.state.preSelected)
|
|
|
|
|
|
|
|
|
|
|
|
if (index !== false) {
|
|
|
|
if (index !== false) {
|
|
|
|
classes.push('field-select__options-item--selected')
|
|
|
|
classes.push('field-select__options-item--selected')
|
|
|
|
@ -280,11 +298,11 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param options object
|
|
|
|
* @param options object
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
searchSelected(option) {
|
|
|
|
search(option, items) {
|
|
|
|
let index = false
|
|
|
|
let index = false
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < this.state.selected.length; i++) {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
if (this.state.selected[i] && this.state.selected[i][ this.state.keys.value ] == option[ this.state.keys.value ]) {
|
|
|
|
if (items[i] && items[i][ this.state.keys.value ] == option[ this.state.keys.value ]) {
|
|
|
|
index = i
|
|
|
|
index = i
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|