मैं रिएक्ट/रेडक्स में एक फॉर्म बनाने की कोशिश कर रहा हूं। अभी के लिए मैं सिर्फ फॉर्म को अपने फ़ंक्शन हैंडल को ट्रिगर करना चाहता हूं सबमिट करें जब फ़ॉर्म सबमिट किया गया हो। हालांकि इस समय ऐसा लगता है कि समारोह पृष्ठ लोड पर तुरन्त शुरू हो रहा है ...रिएक्ट हैंडल फॉर्म सबमिट करें
export default class AssetsAdd extends React.Component {
componentDidMount() {
console.log(this)
}
handleSubmit(event) {
if (this.refs.titleInput !== '') {
event.preventDefault();
var asset = {
date: '',
title : this.refs.titleInput.value,
id : '',
type: this.refs.typeInput.value
}
return this.props.dispatch(addAsset(asset))
}
}
render() {
return (
<div>
<Row>
<Portlet title='New Asset' form>
<Form horizontal onSubmit={this.handleSubmit}>
<FormGroup>
<Label text='Title' size='3' />
<Input ref="titleInput" placeholder='Enter asset title' size='4'/>
</FormGroup>
<FormGroup>
<Label text='Type' size='3' />
<Input ref="typeInput" placeholder='Enter asset type' size='4'/>
</FormGroup>
<FormGroup>
<Label text='Description' size='3' />
<Input ref="descriptionInput" placeholder='Enter asset description' size='4'/>
</FormGroup>
<FormGroup>
<Label text='Documentation' size='3' />
<Input ref="documentationInput" placeholder='Enter documentation URL' size='4'/>
</FormGroup>
<FormActionBar>
<SubmitButton value='Submit'/>
<CancelButton value='Cancel'/>
</FormActionBar>
</Form>
</Portlet>
</Row>
</div>
)
}
}
function mapStateToProps(state) {
return {
assets: state.assets
};
}
export const AssetAddContainer = connect(mapStateToProps)(AssetsAdd);
पर मैं कोड के बाकी सही अभी तक पता नहीं सब है लेकिन मेरी मुख्य चिंता अब सिर्फ ऑनसबमिट कार्रवाई शुरू हो रही है सही समय पर।
अग्रिम धन्यवाद!
2 पहले काम कर रहे हैं लेकिन तीसरा विकल्प काम नहीं कर रहा है। यह इस तरह होना चाहिए: onSubmit = {() => this.handle सबमिट करें()} –