3
0

Fix allow duplicates on user, record and select fields

This commit is contained in:
Jože Fortun
2024-08-14 12:07:18 +02:00
parent 6683568c8a
commit f27ce16ff9
4 changed files with 46 additions and 25 deletions
@@ -340,15 +340,15 @@ export default {
}
},
isSelectable (recordID) {
isSelectable ({ recordID } = {}) {
if (!recordID) {
return false
}
if (this.field.isMulti && !this.field.options.isUniqueMultiValue) {
return this.value !== recordID
if (this.field.isMulti) {
return !this.field.options.isUniqueMultiValue || !this.value.includes(recordID)
} else {
return !(this.value || []).includes(recordID)
return this.value !== recordID
}
},
@@ -56,6 +56,7 @@
:options="selectOptions"
:placeholder="$t('kind.select.placeholder')"
:reduce="o => o.value"
:selectable="isSelectable"
label="text"
@input="selectChange"
/>
@@ -64,8 +65,10 @@
v-if="field.options.selectType === 'multiple'"
v-model="value"
:options="selectOptions"
label="text"
:placeholder="$t('kind.select.placeholder')"
:reduce="o => o.value"
:selectable="isSelectable"
label="text"
multiple
/>
</template>
@@ -77,6 +80,7 @@
:options="selectOptions"
:reduce="o => o.value"
:placeholder="$t('kind.select.placeholder')"
:selectable="isSelectable"
label="text"
/>
@@ -91,10 +95,11 @@
<c-input-select
v-if="field.options.selectType === 'default'"
v-model="value"
:placeholder="$t('kind.select.optionNotSelected')"
:options="selectOptions"
:reduce="o => o.value"
:selectable="isSelectable"
label="text"
:placeholder="$t('kind.select.optionNotSelected')"
/>
<b-form-radio-group
@@ -120,12 +125,7 @@ export default {
computed: {
selectOptions () {
return this.field.options.options.map(o => {
const disabled = o.value && this.field.isMulti && !this.field.options.isUniqueMultiValue
? this.value === o.value
: (this.value || []).includes(o.value)
return { ...o, disabled: this.field.options.selectType !== 'list' && disabled }
}).filter(({ value = '', text = '' }) => value && text)
return this.field.options.options.filter(({ value = '', text = '' }) => value && text)
},
},
@@ -144,6 +144,16 @@ export default {
findLabel (v) {
return (this.selectOptions.find(({ value }) => value === v) || {}).text || v
},
isSelectable ({ value } = {}) {
if (this.field.options.selectType === 'list') return true
if (this.field.isMulti) {
return !this.field.options.isUniqueMultiValue || !(this.value || []).includes(value)
} else {
return this.value !== value
}
},
},
}
</script>
@@ -48,7 +48,7 @@
:get-option-label="getOptionLabel"
:get-option-key="getOptionKey"
:filterable="false"
:selectable="option => option.selectable"
:selectable="isSelectable"
:loading="processing"
@search="search"
@input="updateValue($event)"
@@ -71,7 +71,7 @@
:get-option-label="getOptionLabel"
:get-option-key="getOptionKey"
:filterable="false"
:selectable="option => option.selectable"
:selectable="isSelectable"
:loading="processing"
multiple
@search="search"
@@ -96,7 +96,7 @@
:get-option-key="getOptionKey"
:value="getUserIDByIndex(ctx.index)"
:filterable="false"
:selectable="option => option.selectable"
:selectable="isSelectable"
:loading="processing"
@search="search"
@input="updateValue($event, ctx.index)"
@@ -123,7 +123,7 @@
:value="getUserIDByIndex()"
:clearable="field.name !== 'ownedBy'"
:filterable="false"
:selectable="option => option.selectable"
:selectable="isSelectable"
:loading="processing"
@input="updateValue($event)"
@search="search"
@@ -184,14 +184,7 @@ export default {
}),
options () {
return this.users.map(u => {
return {
...u,
selectable: this.field.isMulti && !this.field.options.isUniqueMultiValue
? this.value !== u.userID
: !(this.value || []).includes(u.userID),
}
})
return this.users
},
// This is used in the case of using the multiple select option
@@ -284,6 +277,18 @@ export default {
return name || username || email || `<@${userID}>`
},
isSelectable ({ userID } = {}) {
if (!userID) {
return false
}
if (this.field.isMulti) {
return !this.field.options.isUniqueMultiValue || !this.value.includes(userID)
} else {
return this.value !== userID
}
},
/**
* Updates record value with user
*
@@ -7,8 +7,9 @@
:options="options"
:searchable="searchable"
:disabled="disabled"
:selectable="selectable"
:calculate-position="calculateDropdownPosition"
:append-to-body="appendToBody"
:append-to-body="appendToBody"
class="bg-white rounded"
:class="sizeClass"
@search="onSearch"
@@ -79,6 +80,11 @@ export default {
type: Boolean,
default: false,
},
selectable: {
type: Function,
default: o => !o.disabled,
},
},
computed: {