Skip to content

Commit 4c40b40

Browse files
committed
fix: add validation error ID to CheckboxSelection and RadioSelection
1 parent 2c21753 commit 4c40b40

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

packages/pluggableWidgets/checkbox-radio-selection-web/src/components/CheckboxSelection/CheckboxSelection.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import classNames from "classnames";
22
import { createElement, MouseEvent, ReactElement } from "react";
33
import { MultiSelector, SelectionBaseProps } from "../../helpers/types";
4+
import { getValidationErrorId } from "../../helpers/utils";
45
import { CaptionContent } from "../CaptionContent";
56
import { ValidationAlert } from "@mendix/widget-plugin-component-kit/Alert";
67
import { Placeholder } from "../Placeholder";
@@ -20,6 +21,7 @@ export function CheckboxSelection({
2021
const name = groupName?.value ?? inputId;
2122

2223
const validation = selector.validation;
24+
const errorId = getValidationErrorId(inputId);
2325

2426
const handleChange = (optionId: string, checked: boolean): void => {
2527
if (!isReadOnly) {
@@ -74,7 +76,7 @@ export function CheckboxSelection({
7476
);
7577
})}
7678
{options.length === 0 && <Placeholder noOptionsText={noOptionsText} />}
77-
{validation && <ValidationAlert>{validation}</ValidationAlert>}
79+
{validation && <ValidationAlert referenceId={errorId}>{validation}</ValidationAlert>}
7880
</div>
7981
);
8082
}

packages/pluggableWidgets/checkbox-radio-selection-web/src/components/RadioSelection/RadioSelection.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import classNames from "classnames";
22
import { ChangeEvent, createElement, MouseEvent, ReactElement } from "react";
33
import { SelectionBaseProps, SingleSelector } from "../../helpers/types";
4+
import { getValidationErrorId } from "../../helpers/utils";
45
import { CaptionContent } from "../CaptionContent";
56
import { ValidationAlert } from "@mendix/widget-plugin-component-kit/Alert";
67
import { Placeholder } from "../Placeholder";
@@ -26,6 +27,7 @@ export function RadioSelection({
2627
const name = groupName?.value ?? inputId;
2728

2829
const validation = selector.validation;
30+
const errorId = getValidationErrorId(inputId);
2931

3032
const handleChange = (e: ChangeEvent<HTMLInputElement>): void => {
3133
if (isReadOnly) {
@@ -92,7 +94,7 @@ export function RadioSelection({
9294
);
9395
})}
9496
{options.length === 0 && <Placeholder noOptionsText={noOptionsText} />}
95-
{validation && <ValidationAlert>{validation}</ValidationAlert>}
97+
{validation && <ValidationAlert referenceId={errorId}>{validation}</ValidationAlert>}
9698
</div>
9799
);
98100
}

packages/pluggableWidgets/checkbox-radio-selection-web/src/helpers/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ export function getCustomCaption(values: CheckboxRadioSelectionPreviewProps): st
5555
}
5656
return emptyStringFormat;
5757
}
58+
59+
export function getValidationErrorId(inputId?: string): string | undefined {
60+
return inputId ? inputId + "-validation-message" : undefined;
61+
}

0 commit comments

Comments
 (0)