Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
data-widget-required
Browse files Browse the repository at this point in the history
  • Loading branch information
pelusanchez committed Dec 26, 2023
1 parent 95839d8 commit 445df84
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/widgets/RequiredErrorMessage.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Error data-error='required'>At least one selection must be made</Error>
)
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/StringChoiceWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ const StringChoiceWidget = ({

const [defaultValue] = selection || []

const requiredError = !bypassed && required && !selection?.length

return (
<Widget data-stylizable='widget'>
<Widget data-stylizable='widget' data-widget-required={requiredError}>
<WidgetHeader>
<WidgetActionsWrapper data-stylizable='widget-action-wrapper'>
<WidgetTitle
Expand Down Expand Up @@ -174,9 +176,7 @@ const StringChoiceWidget = ({
/>
</WidgetHeader>
<ReservedSpace data-stylizable='widget string-choice reserved-error-space'>
{!bypassed && required && !selection?.length ? (
<RequiredErrorMessage />
) : null}
<RequiredErrorMessage show={requiredError} />
</ReservedSpace>
<Fieldset name={name} ref={fieldSetRef} disabled={fieldsetDisabled}>
<Legend>{label}</Legend>
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/StringListArrayWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,10 @@ const StringListArrayWidget = ({

const allValues = getAllValues(allGroups)

const requiredError = !bypassed && required && !selection[name]?.length

return (
<Widget data-stylizable='widget'>
<Widget data-stylizable='widget' data-widget-required={requiredError}>
<WidgetHeader>
<WidgetActionsWrapper data-stylizable='widget-action-wrapper'>
<WidgetTitle
Expand Down Expand Up @@ -430,9 +432,7 @@ const StringListArrayWidget = ({
/>
</WidgetHeader>
<ReservedSpace data-stylizable='widget string-listarray reserved-error-space'>
{!bypassed && required && !selection[name]?.length ? (
<RequiredErrorMessage />
) : null}
<RequiredErrorMessage show={requiredError} />
</ReservedSpace>
<Fieldset name={name} ref={fieldSetRef} disabled={fieldsetDisabled}>
<Legend>{label}</Legend>
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/StringListWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ const StringListWidget = ({
return Boolean(selection.find(sel => sel === value))
}

const requiredError = !bypassed && required && !selection[name]?.length

return (
<Widget data-stylizable='widget'>
<Widget data-stylizable='widget' data-widget-required={requiredError}>
<WidgetHeader>
<WidgetActionsWrapper data-stylizable='widget-action-wrapper'>
<WidgetTitle
Expand Down Expand Up @@ -188,9 +190,7 @@ const StringListWidget = ({
/>
</WidgetHeader>
<ReservedSpace>
{!bypassed && required && !selection[name]?.length ? (
<RequiredErrorMessage />
) : null}
<RequiredErrorMessage show={requiredError} />
</ReservedSpace>
<Fieldset name={name} ref={fieldSetRef} disabled={fieldsetDisabled}>
<Legend>{label}</Legend>
Expand Down

0 comments on commit 445df84

Please sign in to comment.