You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
798 B
22 lines
798 B
export function convertValue(value) {
|
|
return Array.isArray(value) ? [...value] : typeof value === 'string' ? [value] : []
|
|
}
|
|
|
|
export function getSelectIndex(options = [], value = '', multiple = false) {
|
|
const newValue = convertValue(value)
|
|
const values = options.map((n) => n.value || n).filter((n) => !!n)
|
|
if (!multiple) return values.indexOf(newValue[0])
|
|
return newValue.map((n) => values.indexOf(n))
|
|
}
|
|
|
|
export function getRealValue(options = [], value = '', multiple = false) {
|
|
const newValue = convertValue(value)
|
|
const values = options.map((n) => n.value || n).filter((n) => !!n)
|
|
if (!multiple) {
|
|
if (values.includes(newValue[0])) {
|
|
return newValue[0]
|
|
}
|
|
return ''
|
|
}
|
|
return newValue.filter((n) => values.includes(n))
|
|
}
|
|
|