question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set the initial value for Select in FormItem

See original GitHub issue

Select 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:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

68reactions
KrisLeeCodercommented, Mar 9, 2017

Resolved by set the value prop in Option

48reactions
afc163commented, Mar 9, 2017

Select value should be string.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found