大佬教程收集整理的这篇文章主要介绍了必须按两次提交按钮才能提交表单。为什么我必须单击两次才能触发事件?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我不明白哪里出错了?如何让它在第一次点击时起作用?为什么我必须单击两次才能在反应中触发事件? 如果我第一次点击,它不会做任何事情。它仅在第二次单击后提交表单。为什么会这样?如果有人能帮我解决这个问题并告诉我哪里出了问题?
export class Signup extends React.Component {
constructor(props) {
super(props);
this.state = {
full_name: "",email: "",confirm_email: "",password: "",secureEntry: true,showTerms : false,showPrivacy : false,errors : [],termsAccepted : false,buttonActive : false,visible: false,showError: false,}
this.register = this.register.bind(this);
}
onBlur = () => {
var { full_name,email,confirm_email,password,termsAccepteD} = this.state;
var a = full_name.length > 0 && email.length >0 && confirm_email && password.length >0 && termsAccepted
this.setState({ButtonActive: a})
}
OnPressSignin = () => {
this.props.navigation.navigate('Signin');
this.setState({
full_name: "",})
}
onPressBACkbutton = ()=>{
this.props.navigation.goBACk();
this.setState({
full_name: "",})
}
onEndEdiTing = () => {
this.setState({
showError: !this.state.showError
})
}
async componentDIDMount() {}
// check if the input matches the regex requirements or not
valIDateinput = () => {
var errorArray = [];
this.setState({errors:[]});
var { full_name,passworD} = this.state;
//valIDate emty fIEld value
var emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[=+\-^$*.\[\]{}()?"!@#%&/\\,><':;|_~`])\S{8,99}$/;
if(full_name.length == 0 && email.length ==0 && confirm_email.length ==0 && password.length ==0 && !this.state.termsAccepted){
errorArray = [...errorArray,'Attention! Please fill in your name.']
}else{
if(full_name.length == 0){
errorArray = [...errorArray,'Attention! Please fill in your name.']
}
else if(email.length ==0 && confirm_email.length ==0){
console.log("1");
errorArray = [...errorArray,'Attention! Please fill in your email address.']
} else if(email.length ==0){
console.log("3");
errorArray = [...errorArray,'Attention! Please fill in your email address.']
} else if(!emailRegex.test(email)){
console.log("4");
errorArray = [...errorArray,'Attention! Please fill in valID email address.']
} else if(email != confirm_email){
console.log("5");
errorArray = [...errorArray,'Attention! Email and confirm email does not match.']
}
else if(password.length ==0){
console.log("6");
errorArray = [...errorArray,'Attention! Please fill in password.']
}else if(!passwordRegex.test(password)){
console.log("7");
errorArray = [...errorArray,'Attention! Please fill valID password.']
}
else if(!this.state.termsAccepted){
console.log("7");
errorArray = [...errorArray,'Please accept Terms and conditions.']
}
}
console.log("error");
console.log(errorArray);
this.setState({errors: [...errorArray]});
return (errorArray.length <= 0);
}
async register() {
var email = this.state.email;
var password = this.state.password;
var full_name = this.state.full_name;
if(this.state.errors.length > 0 ){
this.setState({
showError: true
})
}
if(this.valIDateinput()){
try {
console.log(' Sign-up Confirmed '+ email +" "+ password);
await Auth.signUp(
{ username: email,password: password,attributes: {
given_name: full_name,email: email,'custom:TOU_version': '1.3','custom:PP_version': '1.3'
}
});
console.log(' Sign-up Confirmed');
this.props.navigation.navigate('SignupConfirmation',{username: email});
} catch (error) {
console.log(' Error signing up...',error);
this.setState({errors:[error.message]});
}
}
}
<touchabLeopacity style={ this.state.buttonActive ? styles.buttonAddFamilyActive : styles.buttonAddFamily }
onPress={this.register}>
<VIEw style={{justifyContent:'space-between',flexDirection:'row'}}>
<VIEw style = {{flex : 1}}>
<VIEw style={{...styles.ikoncontainer,position:'absolute',@R_403_6823@ : 20}}>
</VIEw>
<CText style={{Color:'white',textAlign: 'center',FontWeight:'700',FontSize:15}}>{'submit'}</CText>
</VIEw>
</VIEw>
</VIEw>
);
}
}
```
Here im using Keyboard scrollvIEw,touchable Opacity
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的必须按两次提交按钮才能提交表单。为什么我必须单击两次才能触发事件?全部内容,希望文章能够帮你解决必须按两次提交按钮才能提交表单。为什么我必须单击两次才能触发事件?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。