[Select] Support defaultValue
See original GitHub issue- [x ] This is a v1.x issue (v0.x is no longer maintained).
- [x ] I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
It’s a form used for adding record or edit this record., so when add new record defaultValue has no value but when editing this record, defaultValue will be the value which may be edited.
If I remove value prop, error appear that it’s required prop
Current Behavior
I got this error:
SelectInput contains an input of type hidden with both value and defaultValue props. Input elements must be either controlled or uncontrolled (specify either the value prop, or the defaultValue prop, but not both). Decide between using a controlled or uncontrolled input element and remove one of these props
Context
Your Environment
Tech | Version |
---|---|
Material-UI | v1.0.0 |
React | v16.4.0 |
browser | Chrome v68.0.3440.5 |
etc |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Warning: Use the 'defaultValue' or 'value' props on <select ...
I am using selected attribute on option but React generates a warning asking me to use default value on select. For e.g. render:...
Read more >[Select] Support defaultValue · Issue #11612 · mui/material-ui
The Select component doesn't support the defaultValue prop as we are speaking. The component needs to be controlled but I'm not against ...
Read more >How to set the default value for an HTML <select> element
The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean...
Read more >DefaultValue Property - Microsoft Support
Specifies a String value that is automatically entered in a field when a new record is created. For example, in an Addresses table...
Read more >Default-Value via GET-Parameter in Select-Fields
Is there a way to also pre-populate dropdown menus using a query-string-parameter? Many thanks in advance for your help and have a nice...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@engmagdy87 Maybe we should better warn about it. The Select component doesn’t support the
defaultValue
prop as we are speaking. The component needs to be controlled but I’m not against implementing this behavior.@atifmansoor I don’t think that performance is a concern here. It’s more about code correctness and how easy it’s for somebody to get it right. Regarding implementing the default value behavior. It should be as easy as: