在我的反应应用程序中,我有通用输入组件:
class Input extends Component {
constructor(props) {
super(props);
if (props) {
this.state = {
elementType: props.elementType,
elementConfig: props.elementConfig,
cssClasses: props.cssClasses,
};
}
this.changeValue = this.changeValue.bind(this);
}
render() {
switch (this.state.elementType) {
case ('input'):
inputElement = <input
className={inputClasses.join(' ')}
{...this.state.elementConfig}
value={this.props.getValue() || ''}
onChange={this.changeValue} />;
break;
}
return (
<div className={requiredClass}>
{inputElement}
<span className={'text-danger'}>{requiredMessage}</span>
<span className={'text-danger'}>{errorMessage}</span>
</div>
);
}
}
接下来,我将这组输入与 react-formsy 一起使用:
<Formsy>
<Input
requiredMessage='required'
required
name="checkbox"
elementType="input"
elementConfig={{ type: 'checkbox', id: 'check1'}}
cssClasses={['custom-input']}
/>
<button type="button" disabled={!this.props.canSubmit}></button>
</Formsy>
此复选框应该是必需的,在它们被选中之前,按钮必须处于非活动状态。但问题是我无法选中复选框。我是新来的反应。我的错误在哪里?