有3个复选框,我必须使一个复选框成为必填项。就像所有复选框都未选中一样,应该禁用按钮。请帮我。我该怎么办。
<View style={{ flexDirection: 'row', paddingLeft: 15 }}>
<View style={{ flex: 1 }}>
<CheckBox color="#00678f"
checked={this.state.notification.isContactByPost}
onPress={() => this.handleChange('isContactByPost')}
/>
</View>
<View style={{ flex: 1 }}>
<Text style={{ fontSize: 14 }}>Post</Text>
</View>
<View style={{ flex: 1 }}>
<CheckBox color="#00678f"
checked={this.state.notification.isContactByEmail}
onPress={() => this.handleChange('isContactByEmail')}
/>
</View>
<View style={{ flex: 1 }}>
<Text style={{ fontSize: 14 }}>Email</Text>
</View>
<View style={{ flex: 1 }}>
<CheckBox color="#00678f"
checked={this.state.notification.isContactBySms}
onPress={() => this.handleChange('isContactBySms')}
/>
</View>
<View style={{ flex: 1 }}>
<Text style={{ fontSize: 14 }}>SMS</Text>
</View>
</View>
<View style={{ marginTop: 50 }}>
<PrimaryBtn
label={'submit'}
disabled={false}
onPress={() => this.OnButtonClick(this.state.notification)}
/>
</View>
</View>
谢谢
答案 0 :(得分:2)
这是您可以做到的
<PrimaryBtn label={'submit'} disabled={!this.state.notification.isContactByPost &&
!this.state.notification.isContactByEmail &&
!this.state.notification.isContactBySms} onPress={() =>
this.OnButtonClick(this.state.notification)} />
希望这会有所帮助
答案 1 :(得分:1)
render(){
const {isContactByPost,isContactByEmail,isContactBySms } = this.state.notification;
return (
<PrimaryBtn
label={'submit'}
disabled={!(isContactByPost || isContactByEmail || isContactBySms)}
onPress={() => this.OnButtonClick(this.state.notification)}
/>
);
}
答案 2 :(得分:1)
尝试一下(为了简化起见,我删除了多余的部分)=>
const {isContactByPost, isContactByEmail, isContactBySms} = this.state.notification
const isButtonDisabled = !(isContactByPost || isContactByEmail || isContactBySms)
<PrimaryBtn disabled={isButtonDisabled} /> // don't forget your others props :)