How about `getFieldProps` takes over all the properties of a form control
See original GitHub issueNow, getFieldProps
will take two arguments, then return some properties which will be transfered to form control.
<Select
{...getFieldProps('select', {
rules: [{ required: true }],
})}
placeholder="please select"
/>
However, not all the developers know that getFieldProps
has occupied onChange
(and value
and maybe more event triggers). So, they may write something like this:
<Select
{...getFieldProps('select', {
rules: [{ required: true }],
})}
placeholder="please select"
onChange={handleChange} // Oops...
/>
It seems that getFieldProps
is broken now. Actually, if we want to add an event handler to Select
, we have to do this:
<Select
{...getFieldProps('select', {
rules: [{ required: true }],
onChange: handleChange, // Works fine.
})}
placeholder="please select"
/>
A developer have to know what getFieldProps
will return now. It is not easy, if you are not familiar with getFieldProps
. Because the return value of getFieldProps
depends on the second argument.
But… If getFieldProps
take over all the properties of Select
:
<Select
{...getFieldProps('select', {
rules: [{ required: true }],
props: { // Just pass all the properties to the second argument
placeholder: 'please select',
onChange: handleChange,
},
})}
/>
We don’t need to care about what will getFieldProps
return. What does a developer need to know is: if you use getFieldProps
, all the properties should be passed to option.props
.
After getFieldProps
takes over all the properties, it can check those properties and throw some warning:
- If user set
option.props.defaultValue
, warn: ‘Please setoption.initialValue
, instead of …’ - If user set
option.props.defaultChecked
, warn: ‘Please setoption.initialValue
andoptions. valuePropName
, instead of …’ - …
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:12 (11 by maintainers)
Top GitHub Comments
I think it is ugly for writing or reading. Make Form more complex.
Prefer: https://github.com/ant-design/ant-design/issues/1533#issuecomment-215958946
For it looks like
react-dnd
’s connector… http://gaearon.github.io/react-dnd/docs-drag-source-connector.html#exampleIf you think it’s OK, I will implement this feature in antd@2.0