Update all form components to update bound values before firing onchange events
This commit is contained in:
parent
e3bb206b2d
commit
b70afda93c
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const onChange = e => {
|
const onChange = e => {
|
||||||
dispatch("change", e.detail)
|
|
||||||
value = e.detail
|
value = e.detail
|
||||||
|
dispatch("change", e.detail)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const onChange = e => {
|
const onChange = e => {
|
||||||
dispatch("change", e.detail)
|
|
||||||
value = e.detail
|
value = e.detail
|
||||||
|
dispatch("change", e.detail)
|
||||||
}
|
}
|
||||||
const extractProperty = (value, property) => {
|
const extractProperty = (value, property) => {
|
||||||
if (value && typeof value === "object") {
|
if (value && typeof value === "object") {
|
||||||
|
|
|
@ -46,10 +46,10 @@
|
||||||
let map = null
|
let map = null
|
||||||
if (options?.length) {
|
if (options?.length) {
|
||||||
map = {}
|
map = {}
|
||||||
options.forEach(option => {
|
options.forEach((option, idx) => {
|
||||||
const optionValue = getOptionValue(option)
|
const optionValue = getOptionValue(option, idx)
|
||||||
if (optionValue != null) {
|
if (optionValue != null) {
|
||||||
map[optionValue] = getOptionLabel(option) || ""
|
map[optionValue] = getOptionLabel(option, idx) || ""
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,16 +81,16 @@
|
||||||
</li>
|
</li>
|
||||||
{/if}
|
{/if}
|
||||||
{#if options && Array.isArray(options)}
|
{#if options && Array.isArray(options)}
|
||||||
{#each options as option}
|
{#each options as option, idx}
|
||||||
<li
|
<li
|
||||||
class="spectrum-Menu-item"
|
class="spectrum-Menu-item"
|
||||||
class:is-selected={isOptionSelected(getOptionValue(option))}
|
class:is-selected={isOptionSelected(getOptionValue(option, idx))}
|
||||||
role="option"
|
role="option"
|
||||||
aria-selected="true"
|
aria-selected="true"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
on:click={() => onSelectOption(getOptionValue(option))}>
|
on:click={() => onSelectOption(getOptionValue(option, idx))}>
|
||||||
<span
|
<span
|
||||||
class="spectrum-Menu-itemLabel">{getOptionLabel(option)}</span>
|
class="spectrum-Menu-itemLabel">{getOptionLabel(option, idx)}</span>
|
||||||
<svg
|
<svg
|
||||||
class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon"
|
class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon"
|
||||||
focusable="false"
|
focusable="false"
|
||||||
|
|
|
@ -28,8 +28,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the label if the selected option is found, otherwide raw value
|
// Render the label if the selected option is found, otherwide raw value
|
||||||
const selected = options.find(option => getOptionValue(option) === value)
|
const index = options.findIndex(
|
||||||
return selected ? getOptionLabel(selected) : value
|
(option, idx) => getOptionValue(option, idx) === value
|
||||||
|
)
|
||||||
|
return index !== -1 ? getOptionLabel(options[index], index) : value
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectOption = value => {
|
const selectOption = value => {
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const onChange = e => {
|
const onChange = e => {
|
||||||
dispatch("change", e.detail)
|
|
||||||
value = e.detail
|
value = e.detail
|
||||||
|
dispatch("change", e.detail)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const onChange = e => {
|
const onChange = e => {
|
||||||
dispatch("change", e.detail)
|
|
||||||
value = e.detail
|
value = e.detail
|
||||||
|
dispatch("change", e.detail)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const onChange = e => {
|
const onChange = e => {
|
||||||
dispatch("change", e.detail)
|
|
||||||
value = e.detail
|
value = e.detail
|
||||||
|
dispatch("change", e.detail)
|
||||||
}
|
}
|
||||||
const extractProperty = (value, property) => {
|
const extractProperty = (value, property) => {
|
||||||
if (value && typeof value === "object") {
|
if (value && typeof value === "object") {
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const onChange = e => {
|
const onChange = e => {
|
||||||
dispatch("change", e.detail)
|
|
||||||
value = e.detail
|
value = e.detail
|
||||||
|
dispatch("change", e.detail)
|
||||||
}
|
}
|
||||||
const extractProperty = (value, property) => {
|
const extractProperty = (value, property) => {
|
||||||
if (value && typeof value === "object") {
|
if (value && typeof value === "object") {
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const onChange = e => {
|
const onChange = e => {
|
||||||
dispatch("change", e.detail)
|
|
||||||
value = e.detail
|
value = e.detail
|
||||||
|
dispatch("change", e.detail)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const onChange = e => {
|
const onChange = e => {
|
||||||
dispatch("change", e.detail)
|
|
||||||
value = e.detail
|
value = e.detail
|
||||||
|
dispatch("change", e.detail)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue