Comments (3)
You can leverage hidden input fields i.e <input type="hidden" />
:
import { Autocomplete, Button, TextField } from '@mui/material'
import * as React from 'react'
import { Form, type ActionFunctionArgs } from 'react-router-dom'
const someOptions = [
{ label: 'Option1' },
{ label: 'Option2' },
{ label: 'Option3' },
]
export function AutoCompleteDemo() {
const [selectedOptions, setSelectedOptions] = React.useState([])
return (
<Form method="POST" action="/example">
<Autocomplete
options={someOptions}
getOptionLabel={(option) => option.label}
multiple
onChange={(event, value) => setSelectedOptions(value)}
renderInput={(params) => (
<TextField
{...params}
required
variant="outlined"
label="Example"
/>
)}
/>
{selectedOptions.map((option, index) => (
<input
key={index}
type="hidden"
name="example"
value={option.label}
/>
))}
<Button type="submit">Submit</Button>
</Form>
)
}
export async function AutoCompleDemoAction(args: ActionFunctionArgs) {
const formData = await args.request.formData()
const selectedValues = formData.getAll('example')
console.log(selectedValues)
return true
}
from material-ui.
Thank you for your reply. We know, that we can do it like that ourselves. But this was a feature request to make the access a native functionality – preferably semantically correct, but pure hidden input works as well. Especially since the documentation doesn't remark anywhere, that the single select and multi-select case behave different with regards to FormData
.
In conclusion: we have a workaround like that operating here, but we want MUI's <Autocomplete>
to handle this for us and offer us a "organic" interface to the data – no matter if we have a single or multi-value <Autocomplete>
. ;-)
from material-ui.
@TheRealCuran I'm with you on this one. In the meantime I've shared the wrapper I'm using on #43544 in case it's of any use to you. Also interested to see what you are doing as a workaround.
from material-ui.
Related Issues (20)
- [material-ui] I need that disabling hover on Button HOT 1
- search in Autocomplete HOT 2
- Nested grids for v2 are not behaving the same as in v1 HOT 1
- MuiAutocomplete component- getOptionLabel and aria-label needs to be different, could not able to achieve it HOT 3
- [pigment] Exception when using exported class names from MUI HOT 3
- [docs] MUI-X pages give 404 in v5 docs HOT 2
- [pigment-css][material-ui] Grid throws an error HOT 2
- [material-ui][Dialog] Compatibility between MUI's dialogs and React Hook Form with FormProvider
- [docs] Outdated version entry should be cleaned up and removed from version table
- [Dialog] Providing onKeyDown breaks closing via Escape HOT 3
- [material-ui] Button `color="inherit"` prop regression for `variant="contained"` HOT 1
- [docs] Google Font use is not best practice
- Slide component throws error in Pigment project
- [Grid] Compatible props are no longer warned about in v2 HOT 1
- [docs] useStyles support HOT 1
- [examples] Update examples to use CSS variables HOT 1
- [Autocomplete] A prop is passed containing the `key` HOT 1
- Encountered two children with the same key HOT 1
- [OutlinedInput] No highlighted border on input on mobile HOT 1
- [AppBar] background color not alligned between dark and light colorSchemes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from material-ui.