Reactjs 提交时清除后,所需输入字段变为红色。反应
我有一个表单,它调用redux操作,然后在post成功时清除输入字段。问题似乎是在成功发布后清除输入字段后,输入字段变为红色 重复操作功能Reactjs 提交时清除后,所需输入字段变为红色。反应,reactjs,firefox,axios,Reactjs,Firefox,Axios,我有一个表单,它调用redux操作,然后在post成功时清除输入字段。问题似乎是在成功发布后清除输入字段后,输入字段变为红色 重复操作功能 postActionFunction = (data, clearDataFunction) => (dispatch) => { axios .post(`/endpoint`, data) .then(() => { console.log('success'); }) .then(()
postActionFunction = (data, clearDataFunction) => (dispatch) => {
axios
.post(`/endpoint`, data)
.then(() => {
console.log('success');
})
.then(() => {
clearDataFunction();
})
.catch((err) => {
console.log('error');
});
};
onSubmit(e) {
e.preventDefault();
const { inputData } = this.state;
// below function is the redux action
this.props.postCategories(inputData, this.clearDataFunction);
}
clearDataFunction() {
this.setState({ inputData: '' });
}
表单提交功能
postActionFunction = (data, clearDataFunction) => (dispatch) => {
axios
.post(`/endpoint`, data)
.then(() => {
console.log('success');
})
.then(() => {
clearDataFunction();
})
.catch((err) => {
console.log('error');
});
};
onSubmit(e) {
e.preventDefault();
const { inputData } = this.state;
// below function is the redux action
this.props.postCategories(inputData, this.clearDataFunction);
}
clearDataFunction() {
this.setState({ inputData: '' });
}
编辑:
这似乎只会发生在Firefox开发者版上,这取决于您的验证。显示与验证相关的代码。验证发生在后端,不会返回任何链接到输入字段的内容。html可能会有所帮助,因此在Firefox developer's edition上,字段会变为红色,同时控制台会打印单词
success
?假设success
应该是一个字符串,它只是一个输入错误。是的,字段变为空,控制台中会打印“success”消息。但是田野变红了。
postActionFunction = (data, clearDataFunction) => (dispatch) => {
axios
.post(`/endpoint`, data)
.then(() => {
console.log('success');
})
.then(() => {
clearDataFunction();
})
.catch((err) => {
console.log('error');
});
};
onSubmit(e) {
e.preventDefault();
const { inputData } = this.state;
// below function is the redux action
this.props.postCategories(inputData, this.clearDataFunction);
}
clearDataFunction() {
this.setState({ inputData: '' });
}