New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't set a default value for SelectField #81
Comments
Having the same problem as we speak going to try to dig into it. |
Ok found my issue I was passing immutable values to menuitems and my model had an inmutable value too so they are never the same. Still don't know which is the clearest way to resolve this, probably something like having a function or prop to determine equality is the cleanest but it involves material-ui |
Quick hack using ramda, you probably want to wrap select field to avoid boilerplate <Field
name='foo'
component={SelectField}
hintText='Select Foo'
floatingLabelText='Foo'
format={value => findIndex(propEq('id', value.id))(fooList)}
normalize={value => fooList[value]}
fullWidth
>
{fooList.map((fooElement, i) => (
<MenuItem
value={i}
primaryText={fooElement.name}
/>
))}
</Field> Edit: I ended up with something like this <Field
name='foo'
component={SelectField}
hintText='Foo'
floatingLabelText='Foo'
format={value => value && value.hasOwnProperty('id') ? find(propEq('id', value.id))(fooList) : null}
fullWidth
>
{fooList.map((foo) => (
<MenuItem
key={foo.id}
value={foo}
primaryText={foo.name}
/>
))}
</Field> |
This library doesn't allow defaultValues. You can read more about this here |
As the title says, I'm trying to set an initial value for my select field component and it does not show up as selected when rendered.
If working, example should be added to the live demo.
The text was updated successfully, but these errors were encountered: