-
Can someone help me implement the multi-select with react final form? Right now I'm using react-select with final form, but it's too complicated. I can't retrieve the output as it said Expected array but it's number. How can I convert the select or input type element of useField to receive array? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi Duckinm, I've tried implementing the useField() hook to accomplish multi-select, but had a lot of trouble getting it to work. Here is how I have implemented multi-select in my Blitz apps instead: Multi-selectHere's an example of multi-select implementation in Blitz. In this example, I'm creating a list that allows me to select multiple Star Wars characters. 1. Set up the data modelPut the name of your multi-select field in your data model as a scalar list: model List {
id Int @id @default(autoincrement())
listName String @unique
characters String[]
} 2. Configure mutationsAdd the attribute to your create and edit mutations. Here's what it looks like in the create mutation: const CreateList = z
.object({
listName: z.string(),
characters: z.array(z.string()), //Be sure to convert the array to a string.
})
.nonstrict() 3. Create your dataIn this example, I'm creating some simple data to map through. You can also pull in data from your other models or just create multiple const characters = {
[uuid()]: {
id: 1,
characterName: "Luke Skywalker",
},
[uuid()]: {
id: 2,
characterName: "Leia Organa",
},
[uuid()]: {
id: 3,
characterName: "Han Solo",
},
} 4. Add the
|
Beta Was this translation helpful? Give feedback.
Hi Duckinm,
I've tried implementing the useField() hook to accomplish multi-select, but had a lot of trouble getting it to work. Here is how I have implemented multi-select in my Blitz apps instead:
Multi-select
Here's an example of multi-select implementation in Blitz. In this example, I'm creating a list that allows me to select multiple Star Wars characters.
1. Set up the data model
Put the name of your multi-select field in your data model as a scalar list:
2. Configure mutations
Add the attribute to your create and edit mutations. Here's what it looks like in the cre…