antd design select placeholder issues
17,038
Solution 1
set this.state.company to be undefined instead of null.
Solution 2
you should update as below:
<Select
showSearch
optionFilterProp = "children"
placeholder = "Select Company"
value = {this.state.company || undefined} ---- update this line
name = "company"
onSelect = "{this.handleCompanyChange}"
>
Solution 3
It should be set to undefined
instead of null
or ""
empty string.
this.props.form.setFieldsValue({
myFieldName: undefined
})
Solution 4
I have faced the the same issue, heres the solution: Code snippet for ant design select
<Select key="1" value={this.getStateValue()} showSearch allowClear placeholder='Select Weight' onChange={onWeightChange}>
{options}
</Select>
where getStateValue will be this:
getStateValue = () => {
const { value } = this.state;
if (value) {
return value;
}
}
Related videos on Youtube
Author by
FE_Addict
Updated on June 27, 2022Comments
-
FE_Addict almost 2 years
I am using antd design in my React app.
Here's a code snippet where I am facing the issues :
<Select showSearch optionFilterProp = "children" placeholder = "Select Company" value = "{this.state.company}" name = "company" onSelect = "{this.handleCompanyChange}" >
Now it shows the correct value selected if
this.state.company
is notnull
. But ifthis.state.company
isempty
ornull
, placeholder doesn't shows up.How can I solve this issue so that the placeholder appears if
value
is null? -
FE_Addict almost 7 yearsDo you mean like this : this.state.company=undefined ?
-
NSjonas almost 6 years
value = {this.state.company?this.state.company:undefined}
-
0xh8h over 4 yearsYou can also simplify the above statement with value={this.state.company || undefined}
-
devuxer over 4 years@afc163, Can you guys fix this? It should show the placeholder for null too.
-
blueseal about 4 yearsshortcut
value = { this.state.company || undefined }
-
Jyoti Duhan over 3 yearshi, It's is not working for me: <Select showSearch placeholder="Select category" value={undefined}>
-
Kelwin Tantono over 2 yearsyou should put something to the value instead of just undefined @JyotiDuhan, but can you explain why should it be undefined?