我有一種從服務器獲取數據並顯示到文本字段的表單。雖然數據在文本字段中,但當我點擊保存按鈕時,出現錯誤顯示以下字段的所有字段不能爲空。此外,當我嘗試更改值,我不能輸入任何文本既不能刪除文本。爲什麼價值在那裏有價值時顯示爲空?即使在文本字段中有值後也顯示爲空值
const mapStateToProps = createStructuredSelector({
cloudinaryData: selectCloudinary()
});
class Cloudinary extends React.Component {
state = {
cloudinary: {
cloudinary_cloud_name: "",
cloudinary_api_key: "",
},
errors: {}
};
componentDidMount() {
this.props.loadCloudinary();
}
handleChange = event => {
const fieldName = event.target.name;
this.setState(
{
cloudinary: {
...this.state.cloudinary,
[event.target.name]: event.target.value
}
},
() => {
this.validateField([fieldName]);
}
);
};
handleSubmit = event => {
event.preventDefault();
this.props.requestCloudinary(this.state.cloudinary);
};
render() {
const { cloudinary, errors } = this.state;
const { cloudinaryData } = this.props;
if (cloudinaryData.size === 0) {
return <div>Fetching Data...</div>;
}
return (
<form onSubmit={this.handleSubmit}>
<TextFieldGroup
name="cloudinary_cloud_name"
type="text"
value={
cloudinaryData
? cloudinaryData.cloudinary_cloud_name
: cloudinary.cloudinary_cloud_name
}
onChange={this.handleChange}
onBlur={this.handleBlur}
error={errors.cloudinary_cloud_name}
/>
<button className="btn btn-primary">Save changes</button>
</form>
);
}
}
請使用Stack Snippets('[<>]'工具欄按鈕)使用** runnable ** [mcve]更新您的問題。 Stack Snippets支持React,包括JSX; [這是如何做一個](http://meta.stackoverflow.com/questions/338537/)。 –