Skip to content

Commit

Permalink
🩹 [open-formulieren/open-forms#2081] Check if the submit is triggered…
Browse files Browse the repository at this point in the history
… by a submit button
  • Loading branch information
SilviaAmAm committed Sep 27, 2022
1 parent c05a5fd commit 70b45e8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/components/FormStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Card from 'components/Card';
import FormStepDebug from 'components/FormStepDebug';
import Loader from 'components/Loader';
import FormStepSaveModal from 'components/modals/FormStepSaveModal';
import {findPreviousApplicableStep, isLastStep} from 'components/utils';
import {eventTriggeredBySubmitButton, findPreviousApplicableStep, isLastStep} from 'components/utils';
import ButtonsToolbar from 'components/ButtonsToolbar';
import {ConfigContext, FormioTranslations} from 'Context';
import { ValidationError } from 'errors';
Expand Down Expand Up @@ -418,6 +418,12 @@ const FormStep = ({
// into that to handle the actual submission.
const onReactSubmit = async (event) => {
event.preventDefault();

// Issue #2081 - The button to save a row of an editgrid triggers a submit if there are validation errors
if(!eventTriggeredBySubmitButton(event)) {
return;
}

if (!canSubmit) return;

// current is the component, current.instance is the component instance, and that
Expand Down
19 changes: 18 additions & 1 deletion src/components/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,21 @@ const getLoginRedirectUrl = (form) => {
}
}

export {findNextApplicableStep, findPreviousApplicableStep, isLastStep, getLoginRedirectUrl, getLoginUrl};
const eventTriggeredBySubmitButton = (event) => {
const submitterAttributes = event.nativeEvent.submitter.attributes;

for (const attribute of submitterAttributes) {
if (attribute.name === 'type' && attribute.value === 'submit') return true;
}

return false;
};

export {
findNextApplicableStep,
findPreviousApplicableStep,
isLastStep,
getLoginRedirectUrl,
getLoginUrl,
eventTriggeredBySubmitButton,
};

0 comments on commit 70b45e8

Please sign in to comment.