PickerSelect
Popup-based select box
Template Dialog Table Picker Example
<script setup lang="tsx">
import { createForm } from '@silver-formily/core'
import { FormDialog, FormItem, PickerSelect, SelectTable, Submit } from '@silver-formily/element-plus'
import { Field, FormProvider } from '@silver-formily/vue'
const form = createForm()
const userRows = [
{ id: 'u1', name: 'Ada Lovelace', team: 'Math' },
{ id: 'u2', name: 'Grace Hopper', team: 'Compiler' },
{ id: 'u3', name: 'Linus Torvalds', team: 'Kernel' },
]
const userOptions = userRows.map(item => ({
label: `${item.name} / ${item.team}`,
value: item.id,
raw: item,
}))
function openUserPicker({ field }) {
return FormDialog('Select Members', () => (
<Field
name="users"
component={[
SelectTable,
{
rowKey: 'id',
optionAsValue: true,
columns: [
{ prop: 'name', label: 'Name' },
{ prop: 'team', label: 'Team' },
],
},
]}
dataSource={userRows}
/>
))
.forOpen((payload, next) => {
next({
...payload,
initialValues: {
users: userRows.filter(item => field?.value?.includes?.(item.id)),
},
})
})
.open()
.then(values => values.users.map(item => ({
label: `${item.name} / ${item.team}`,
value: item.id,
raw: item,
})))
}
function log(value: any) {
console.log(value)
}
</script>
<template>
<FormProvider :form="form">
<Field
name="users"
title="Members"
:decorator="[FormItem]"
:component="[
PickerSelect,
{
multiple: true,
clearable: true,
collapseTags: true,
collapseTagsTooltip: true,
openPicker: openUserPicker,
placeholder: 'Click to select members',
},
]"
:initial-value="['u1', 'u2', 'u3']"
:data-source="userOptions"
/>
<Submit style="margin-top: 16px" @submit="log">
Submit
</Submit>
</FormProvider>
</template>Members:
查看源码
API
See https://element-plus.org/en-US/component/select.html
Extended Props
| Prop | Type | Description | Default |
|---|---|---|---|
options | PickerSelectOption[] | Candidate option list. In most cases, prefer injecting it through dataSource. | [] |
openPicker | function | Picker function triggered when the selector is clicked. Usually returns the option or options returned by FormDialog(...).open(). | - |
cacheSelectedOptions | boolean | Whether to cache options returned by openPicker so labels can be displayed before dataSource catches up. | true |
Tip
openPickerreturns a PickerSelectOption object instead of the rawFieldvalue.- When
cacheSelectedOptionsis enabled, those option objects are cached andField.valueis taken from theirvaluefield. When disabled, you need to load the correspondingdataSourceyourself, for example when an initial value exists before the dialog is opened. - When the current field value cannot be matched in
dataSource, the component falls back to displaying the rawvalue.
PickerSelectOption
ts
interface PickerSelectOption {
label: string
value: any
disabled?: boolean
// Extend with other business fields. The component does not read them internally.
}Slots
The component inherits the common display slots from ElSelect. The first version mainly keeps the original behavior of prefix, empty, tag, loading, and label, without adding extra scope protocol.