How to set the initial value for Select in FormItem
See original GitHub issueSelect in FormItem:
<FormItem
{...formItemLayout}
label="Select your favorite"
>
{getFieldDecorator("g24_channel", {
initialValue: 0
})(
<Select>
{ favorite.map(item => <Option key={item.id}>{item.text}</Option>) }
</Select>
)}
</FormItem>
If favorite
is const favorite = [{id: 0, text: "apple"}, {id: 1, text: "banana"}];
, it will display 0
, not apple
, by default on select.
If favorite
is a ajax result set in state
, it will also display 0
.
But I’m really intend to display the default option text banana
.
BTW, the above code has a error in console:
Warning: Failed prop type: Invalid prop 'value' supplied to 'Select'.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Antd Select not setting initial value - Stack Overflow
The below is a simple demo of Select Component in Antd Form I am wondering whether the options come from the store or...
Read more >Select - Ant Design
Select component to select value from options. When To Use. A dropdown menu for displaying choices - an elegant alternative to the native...
Read more >antd-select-default-value-bug - CodeSandbox
antd-select-default-value-bug. 1. Embed Fork Create Sandbox ... Forked Fromagitated-wildflower-i0fyv; Environmentcreate-react-app. Files. index.css.
Read more >Default value of input component (Select) is not used while ...
Then if initialValues prop is provided in Form then the value in Select ... When you add input item into the Form and...
Read more >How to set the initial value for Mutlti Select in FormItem in ...
[Solved]-How to set the initial value for Mutlti Select in FormItem in ANTD-Reactjs. Search. score:2. Accepted answer. const [defaultsites, setDefaultSites] ...
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
Resolved by set the value prop in Option
Select value should be string.