Skip to content

Commit

Permalink
Merge pull request #1694 from creative-commoners/pulls/2/support-nest…
Browse files Browse the repository at this point in the history
…ed-forms

FIX Support nested redux forms
  • Loading branch information
sabina-talipova authored Mar 1, 2024
2 parents d6d71df + 60563db commit 0c5de61
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 0c5de61

Please sign in to comment.