diff --git a/src/widgets/RequiredErrorMessage.tsx b/src/widgets/RequiredErrorMessage.tsx index 478c79a..35629c7 100644 --- a/src/widgets/RequiredErrorMessage.tsx +++ b/src/widgets/RequiredErrorMessage.tsx @@ -1,7 +1,11 @@ import React from 'react' import { Error } from './Widget' -export const RequiredErrorMessage = () => { +export const RequiredErrorMessage = ({ show = false }: { show?: boolean }) => { + if (!show) { + return null + } + return ( At least one selection must be made ) diff --git a/src/widgets/StringChoiceWidget.tsx b/src/widgets/StringChoiceWidget.tsx index 0cde4f9..323dd6e 100644 --- a/src/widgets/StringChoiceWidget.tsx +++ b/src/widgets/StringChoiceWidget.tsx @@ -140,8 +140,10 @@ const StringChoiceWidget = ({ const [defaultValue] = selection || [] + const requiredError = !bypassed && required && !selection?.length + return ( - + - {!bypassed && required && !selection?.length ? ( - - ) : null} +
{label} diff --git a/src/widgets/StringListArrayWidget.tsx b/src/widgets/StringListArrayWidget.tsx index dc3f33f..6ae0098 100644 --- a/src/widgets/StringListArrayWidget.tsx +++ b/src/widgets/StringListArrayWidget.tsx @@ -354,8 +354,10 @@ const StringListArrayWidget = ({ const allValues = getAllValues(allGroups) + const requiredError = !bypassed && required && !selection[name]?.length + return ( - + - {!bypassed && required && !selection[name]?.length ? ( - - ) : null} +
{label} diff --git a/src/widgets/StringListWidget.tsx b/src/widgets/StringListWidget.tsx index 57760e4..6db4e2f 100644 --- a/src/widgets/StringListWidget.tsx +++ b/src/widgets/StringListWidget.tsx @@ -122,8 +122,10 @@ const StringListWidget = ({ return Boolean(selection.find(sel => sel === value)) } + const requiredError = !bypassed && required && !selection[name]?.length + return ( - + - {!bypassed && required && !selection[name]?.length ? ( - - ) : null} +
{label}