redux 形式的数据绑定单选字段
data-binding radio field in redux-form
我正在使用 redux-form v8.1.0。
数据库中有一个布尔字段 IsCompulsary。
如何让'Yes'判断为真,'No'判断为假?
<div>
<label>
<Field
name="IsCompulsary"
component="input"
type="radio"
/>{' '}
Yes
</label>
<label>
<Field
name="IsCompulsary"
component="input"
type="radio"
/>{' '}
No
</label>
</div>
更新:
组件底部:
SchoolSettings = reduxForm({
form: "schoolSettingsForm", // a unique identifier for this form
enableReinitialize: true
})(SchoolSettings);
SchoolSettings = connect(
state => ({
initialValues: state.schoolSettings.data // pull initial values from account reducer
})
)(SchoolSettings);
export default SchoolSettings;
数据是:
{Id: 1, Name: "Our School", IsCompulsary: true}
您需要将值字段添加到无线电输入并规范化它们的值,以便在更新商店之前将它们转换为布尔值:
<div>
<label>
<Field
name="IsCompulsary"
component="input"
type="radio"
value={true}
normalize={value => value === 'true'}
/>{' '}
Yes
</label>
<label>
<Field
name="IsCompulsary"
component="input"
type="radio"
value={false}
normalize={value => value === 'true'}
/>{' '}
No
</label>
</div>
我正在使用 redux-form v8.1.0。 数据库中有一个布尔字段 IsCompulsary。 如何让'Yes'判断为真,'No'判断为假?
<div>
<label>
<Field
name="IsCompulsary"
component="input"
type="radio"
/>{' '}
Yes
</label>
<label>
<Field
name="IsCompulsary"
component="input"
type="radio"
/>{' '}
No
</label>
</div>
更新:
组件底部:
SchoolSettings = reduxForm({
form: "schoolSettingsForm", // a unique identifier for this form
enableReinitialize: true
})(SchoolSettings);
SchoolSettings = connect(
state => ({
initialValues: state.schoolSettings.data // pull initial values from account reducer
})
)(SchoolSettings);
export default SchoolSettings;
数据是:
{Id: 1, Name: "Our School", IsCompulsary: true}
您需要将值字段添加到无线电输入并规范化它们的值,以便在更新商店之前将它们转换为布尔值:
<div>
<label>
<Field
name="IsCompulsary"
component="input"
type="radio"
value={true}
normalize={value => value === 'true'}
/>{' '}
Yes
</label>
<label>
<Field
name="IsCompulsary"
component="input"
type="radio"
value={false}
normalize={value => value === 'true'}
/>{' '}
No
</label>
</div>