Skip to content

Commit

Permalink
Add changes to select configurator and editor
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmyMay committed Jul 7, 2023
1 parent 11c01c2 commit 35933db
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
Expand Up @@ -79,12 +79,14 @@
stacked
@change="onUpdateIsUniqueMultiValue"
/>
</b-form-group>

<b-form-group>
<b-form-checkbox
v-if="f.options.selectType !== 'multiple'"
v-model="f.options.isUniqueMultiValue"
:value="false"
:unchecked-value="true"
class="mt-2"
>
{{ $t('kind.select.allow-duplicates') }}
</b-form-checkbox>
Expand Down
Expand Up @@ -114,9 +114,11 @@
v-model="f.options.selectType"
:options="selectOptions"
stacked
@change="onUpdateIsUniqueMultiValue"
@change="updateIsUniqueMultiValue"
/>
</b-form-group>

<b-form-group>
<b-form-checkbox
v-if="shouldAllowDuplicates"
v-model="f.options.isUniqueMultiValue"
Expand Down Expand Up @@ -151,11 +153,12 @@ export default {
data () {
return {
newOption: { value: undefined, text: undefined, new: true },
selectOptionss: [
{ text: this.$t('kind.select.optionType.default'), value: 'default' },
options: [
{ text: this.$t('kind.select.optionType.default'), value: 'default', allowMulti: true, allowDuplicates: true },
{ text: this.$t('kind.select.optionType.multiple'), value: 'multiple' },
{ text: this.$t('kind.select.optionType.each'), value: 'each' },
{ text: this.$t('kind.select.optionType.list'), value: 'list' },
{ text: this.$t('kind.select.optionType.each'), value: 'each', allowDuplicates: true },
{ value: 'list', allowMulti: true },
],
}
},
Expand Down Expand Up @@ -186,20 +189,26 @@ export default {
},
selectOptions () {
const options = [
{ text: this.$t('kind.select.optionType.default'), value: 'default' },
{ text: this.$t('kind.select.optionType.multiple'), value: 'multiple' },
{ text: this.$t('kind.select.optionType.each'), value: 'each' },
{ text: this.$t('kind.select.optionType.list'), value: 'list' },
]
if (!this.f.isMulti) {
return options.filter(o => o.value === 'list' || o.value === 'default')
const selectOptions = this.options.map((o) => {
if (o.value === 'list') {
o.text = this.$t(`kind.select.optionType.${this.f.isMulti ? 'checkbox' : 'radio'}`)
}
return o
})
if (this.f.isMulti) {
return selectOptions
}
return options
return selectOptions.filter(({ allowMulti }) => allowMulti)
},
shouldAllowDuplicates () {
return this.f.options.selectType !== 'multiple' && this.f.isMulti && this.f.options.selectType !== 'list'
if (!this.f.isMulti) return false
const { allowDuplicates } = this.options.find(({ value }) => value === this.f.options.selectType) || {}
return !!allowDuplicates
},
},
Expand All @@ -220,10 +229,10 @@ export default {
})
},
onUpdateIsUniqueMultiValue () {
if (this.f.options.selectType === 'multiple') {
this.f.options.isUniqueMultiValue = true
}
updateIsUniqueMultiValue (value) {
const { allowDuplicates = false } = this.options.find(({ value: v }) => v === value) || {}
if (this.f.options.selectType !== 'multiple') return
this.f.options.isUniqueMultiValue = !allowDuplicates
},
},
}
Expand Down
Expand Up @@ -37,12 +37,14 @@
stacked
@change="onUpdateIsUniqueMultiValue"
/>
</b-form-group>

<b-form-group>
<b-form-checkbox
v-if="f.options.selectType !== 'multiple'"
v-model="f.options.isUniqueMultiValue"
:value="false"
:unchecked-value="true"
class="mt-2"
>
{{ $t('kind.select.allow-duplicates') }}
</b-form-checkbox>
Expand Down
3 changes: 2 additions & 1 deletion locale/en/corteza-webapp-compose/field.yaml
Expand Up @@ -119,7 +119,8 @@ kind:
each: Input for each value
label: Select type
multiple: Multiple select
list: List View
checkbox: Checkbox Group
radio: Radio Group
optionValuePlaceholder: Value
optionsLabel: Options to select from
placeholder: Select an option by clicking here
Expand Down

0 comments on commit 35933db

Please sign in to comment.