Skip to content

Commit

Permalink
Merge pull request #559 from open-formulieren/issue/3511-blinking-use…
Browse files Browse the repository at this point in the history
…r-input

Fix flickering inputs on Webkit browsers
  • Loading branch information
sergei-maertens authored Sep 29, 2023
2 parents 1f64a86 + dde08a5 commit bd7e2de
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/components/FormStep/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class AbortedLogicCheck extends Error {
const initialState = {
configuration: null,
backendData: {},
formioInitialized: false,
canSubmit: false,
logicChecking: false,
isFormSaveModalOpen: false,
Expand Down Expand Up @@ -212,6 +213,7 @@ const reducer = (draft, action) => {
} = action.payload;
draft.configuration = configuration;
draft.backendData = data;
draft.formioInitialized = false;
draft.canSubmit = canSubmit;
draft.logicChecking = false;
draft.isNavigating = false;
Expand All @@ -223,6 +225,11 @@ const reducer = (draft, action) => {
break;
}

case 'FORMIO_INITIALIZED': {
draft.formioInitialized = true;
break;
}

case 'BLOCK_SUBMISSION': {
const {logicChecking = false} = action.payload || {};
draft.canSubmit = false;
Expand Down Expand Up @@ -305,6 +312,7 @@ const FormStep = ({
{
configuration,
backendData,
formioInitialized,
canSubmit,
logicChecking,
isFormSaveModalOpen,
Expand Down Expand Up @@ -708,6 +716,14 @@ const FormStep = ({
return;
}

// formio initialized also fires when the formio configuration changes bceause of
// logic, but we only tap into this hook to set the backend-loaded submission data.
// Once this is done, we don't want to run anything anymore.
// Otherwise this causes problems wich change events triggering and "bouncing" back
// and forth (in WebKit browsers) with the logic check via the onFormIOChange, see
// open-formulieren/open-forms#3511.
if (formioInitialized) return;

// We cannot filter 'blank' values to prevent Formio validation from running, as
// Formio will use the default values in that case which have been explicitly
// unset. In the situation that we have invalid backend data (loading a submission
Expand All @@ -722,6 +738,7 @@ const FormStep = ({
// for FormIO (multivalue input is one example why that's needed).
formInstance.setSubmission({data: cloneDeep(backendData)}, {noValidate: true});
}
dispatch({type: 'FORMIO_INITIALIZED'});
};

/**
Expand Down

0 comments on commit bd7e2de

Please sign in to comment.