Skip to content

Commit

Permalink
FIX Support nested redux forms
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Feb 27, 2024
1 parent d6d71df commit 60563db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion client/src/components/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import FormAlert from 'components/FormAlert/FormAlert';
import PropTypes from 'prop-types';

class Form extends Component {
constructor(props) {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
}

componentDidMount() {
if (!this.props.autoFocus) {
return;
Expand Down Expand Up @@ -39,6 +44,13 @@ class Form extends Component {
return null;
}

handleSubmit(event, ...args) {
// Ensure submitting a nested form doesn't submit the parent form
event.stopPropagation();
// Pass submission handling up the component stack
this.props.handleSubmit(event, ...args);
}

render() {
const valid = this.props.valid !== false;
const fields = this.props.mapFieldsToComponents(this.props.fields);
Expand All @@ -55,7 +67,7 @@ class Form extends Component {
}
const formProps = {
...this.props.attributes,
onSubmit: this.props.handleSubmit,
onSubmit: this.handleSubmit,
className: className.join(' '),
};

Expand Down

0 comments on commit 60563db

Please sign in to comment.