reactjs - 如何在编辑表单选项时禁用下拉菜单?
问题描述
<FormField
form={props.form}
name={'DataLocationId'}
label={t('projectForm.field.dataCenter.label')}
fieldType={'select'}
message={`${t('common.required')}`}
required
options={dataLocations}
isDisabled={true}
selected={dataLocations.find(d => d.value === initialProperties?.DataLocationId)}
/>
case 'select':
return (
<Field
name={this.props.name}
label={this.props.label}
conf={this.props}
component={SelectField}
className="bnt-hc-inputs-input"
type="select"
options={this.props.options}
form={this.props.form}
selected={this.props.selected}
/>
);
如果已在编辑表单选项中选择了该值,我想禁用下拉菜单。我已经添加了Isdisabled ={true}
,但它不起作用。
解决方案
将 isDisabled 传递给 Field 可能会解决您的问题;
case 'select':
return (
<Field
name={this.props.name}
label={this.props.label}
conf={this.props}
component={SelectField}
className="bnt-hc-inputs-input"
type="select"
options={this.props.options}
form={this.props.form}
selected={this.props.selected}
disabled={this.props.isDisabled} // <-- this is the line you need to add
/>
);
假设Field
组件已禁用道具
推荐阅读
- flutter - 如何从 Firestore 文档的一个字段中获取数据?
- list - 根据其他数据列表创建值列表(谷歌表脚本)
- swift - Facebook“抱歉出了点问题”迅速
- android - FFmpeg Android 连接。“–safe 0”是无效参数
- discord.js - 如何将用户在消息反应中限制为 1 种选择?
- user-interface - Flutter:如何添加神经拟态梯度?
- android - View.SYSTEM_UI_FLAG_FULLSCREEN 无法正常工作
- python - 连接到 IB 代理 API PYTHON
- django-models - 如何在 Django 3 中关联单独的模型
- java - 如何使用 JPA 存储通用实体?