I'm using react-bootstrap to launch a modal form.
To do that I created a modal component PopupForm
, a form component ProductForm
, a product component, in the product component I call
<ModalTrigger
modal={<PopupForm form={<ProductForm ref="pform" data={this.props.prod_data} />}/>}>
<Button bsStyle='primary' bsSize='small' style={{marginRight:'5px'}} >
<span className="glyphicon glyphicon-pencil" />
</Button>
</ModalTrigger>
PopupForm
:
var PopupForm = React.createClass({
render: function(){
return (
<Modal {...this.props} bsStyle='primary'
style={{width:200}} title='Edition' animation={false}>
<div className='modal-body'>
{this.props.form}
</div>
<div className='modal-footer'>
<Button onClick={this.props.form.submit()}>Editer</Button>
<Button onClick={this.props.onRequestHide}>Close</Button>
</div>
</Modal>
)
}
});
On this onClick
Editer, I would like to call the method submit
of the ProductForm
component, the ProductForm
component is send to PopupForm
in the prop form, I display it like this {this.props.form}
, but I can't call the method {this.props.form.submit()}
Actually I'd like to use the modal button to trigger ProductForm method if it's not possible I will use a submit button inside the ProductForm.
Here is my ProductForm
:
var ProductForm = React.createClass({
componentDidMount: function() {
this.props.submit = this.submit;
},
getInitialState: function () {
return {canSubmit: false};
},
enableButton: function () {
this.setState({
canSubmit: true
});
},
disableButton: function () {
this.setState({
canSubmit: false
});
},
submit: function (model) {
alert('ok');
},
render: function () {
return (
<Formsy.Form className="" name="test" onValidSubmit={this.submit} onValid={this.enableButton} onInvalid={this.disableButton}>
<CsInput value={this.props.data.name}
label="Nom" id="product_name"
name={this.props.data.name}
validations={{matchRegexp: /^[A-Za-z0-9]{1,30}$/}}
validationError={validations_errors[1]} required/>
{/*<button type="submit" disabled={!this.state.canSubmit}>Submit</button>*/}
</Formsy.Form>
);
}
});
Thanks in advance.