diff --git a/airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/ConditionSection.tsx b/airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/ConditionSection.tsx index fed6d6e17b46..25db411c7ef6 100644 --- a/airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/ConditionSection.tsx +++ b/airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/ConditionSection.tsx @@ -1,5 +1,5 @@ import { useFormikContext, setIn } from "formik"; -import React, { useCallback, useMemo } from "react"; +import React, { useCallback, useEffect, useMemo, useRef } from "react"; import styled from "styled-components"; import { Label, DropDown } from "components"; @@ -37,7 +37,8 @@ interface ConditionSectionProps { */ export const ConditionSection: React.FC = ({ formField, path, disabled }) => { const { widgetsInfo, setUiWidgetsInfo } = useServiceForm(); - const { values, setValues } = useFormikContext(); + const { values, setValues, validateForm } = useFormikContext(); + const shouldValidateRef = useRef(false); const currentlySelectedCondition = widgetsInfo[formField.path]?.selectedItem; @@ -56,12 +57,15 @@ export const ConditionSection: React.FC = ({ formField, p ) : values; + // Wait until the form state updates to run validation with the updated schema + shouldValidateRef.current = true; + + setValues(newValues, false); setUiWidgetsInfo(formField.path, { selectedItem: selectedItem.value, }); - setValues(newValues); }, - [values, formField.conditions, setValues, setUiWidgetsInfo, formField.path] + [formField.conditions, formField.path, values, setValues, setUiWidgetsInfo] ); const options = useMemo( @@ -72,7 +76,16 @@ export const ConditionSection: React.FC = ({ formField, p })), [formField.conditions] ); + + useEffect(() => { + if (shouldValidateRef.current) { + validateForm(); + shouldValidateRef.current = false; + } + }, [validateForm, widgetsInfo]); + const label = formField.title || formField.fieldKey; + const blocks = formField.conditions[currentlySelectedCondition]; return ( = ({ formField, p } > - + );