Is there anyway to access the component method of a redux-form. I want my upload button to submit the form and also if user haven't select any file, then I will open the file select dialog.
My code
UploadModal.js
import React from 'react';
import Form from './components/Form';
class UploadModal extends React.Component {
constructor(props) {
super(props)
this.onSubmit = this.onSubmit.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
onSubmit() {
// call open file select dialog if haven't select any file
this.refs.form.submit();
}
handleSubmit(values) {
//handling submit
}
render() {
return (
<div>
<p>Upload files</p>
<Form ref="form" onSubmit={this.handleSubmit} />
<Button onClick={this.onSubmit}>Upload</Button>
</div>
)
}
}
Form.js
import React from 'react';
import { reduxForm } from 'redux-form';
import Dropzone from 'react-dropzone';
class Form extends React.Component {
constructor(props) {
super(props)
}
onOpenDialog() {
// I want to access this method from Upload Modal
this.refs.dropZone.open();
}
render() {
return (
<div>
<Dropzone ref="dropZone">
<p>Please select file to upload</p>
</Dropzone>
</div>
)
}
export default reduxForm({
form: 'upload',
fields: ['file'],
})(Form)