Skip to content

Commit

Permalink
Merge pull request #1685 from creative-commoners/pulls/2/bypass-entwine
Browse files Browse the repository at this point in the history
FIX Enable bypassing entwine onsubmit handler
  • Loading branch information
Maxime Rainville authored Apr 15, 2024
2 parents 5f169e1 + 6413543 commit 72371d7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions client/src/components/FormBuilder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ the submission process works as follows:

See [handleSubmit](http://redux-form.com/6.0.5/docs/api/Props.md#-handlesubmit-eventorsubmit-function-)
in the redux-form docs for more details.

Note that submissions from a `<FormBuilder>` component that rendered inside part of a regular edit form may
have their submission event intercepted by entwine by `onsubmit` in `LeftAndMain.EditForm.js`. You
can add a `bypass-entwine` class to your react component to prevent this behaviour.
5 changes: 3 additions & 2 deletions client/src/components/Toasts/Toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ const Toast = ({ type, text, onDismiss, dismissed, actions }) => {

Toast.propTypes = {
...toastShape,
onDismiss: PropTypes.func.isRequired
onDismiss: PropTypes.func
};

Toast.defaultProps = {
actions: []
actions: [],
onDismiss: () => {},
};

export default Toast;
5 changes: 5 additions & 0 deletions client/src/legacy/LeftAndMain.EditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ $.entwine('ss', function($){
* Suppress submission unless it is handled through ajaxSubmit().
*/
onsubmit: function(e, button) {
// If the submit button a child of on an element with a .bypass-entwine-submission class on it then
// skip handling. Usually the element in question will be used by react e.g. FormBuilder
if ($(e.target.activeElement).closest('.bypass-entwine-submission').length) {
return true;
}
// Only submit if a button is present.
// This supressed submits from ENTER keys in input fields,
// which means the browser auto-selects the first available form button.
Expand Down

0 comments on commit 72371d7

Please sign in to comment.