我正在使用 react-bootstrap 启动模态表单。
为此,我在我调用的产品组件中创建了一个模态组件PopupForm
、一个表单组件ProductForm
、一个产品组件
<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>
)
}
});
在这个onClick
编辑器上,我想调用组件的方法,submit
组件以prop形式发送到,我这样显示,但我不能调用方法
实际上我想使用模态按钮来如果不可能,则触发 ProductForm 方法我将在 ProductForm 中使用提交按钮。ProductForm
ProductForm
PopupForm
{this.props.form}
{this.props.form.submit()}
这是我的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>
);
}
});
提前致谢。