Extract field errors into a separate component
This commit is contained in:
parent
319927e1dc
commit
9c6e3da304
@ -80,7 +80,6 @@ export function UserProfileFormFields(props: UserProfileFormFieldsProps) {
|
|||||||
i18n={i18n}
|
i18n={i18n}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className={formGroupClassName}
|
className={formGroupClassName}
|
||||||
style={{
|
style={{
|
||||||
@ -121,21 +120,12 @@ export function UserProfileFormFields(props: UserProfileFormFieldsProps) {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{displayableErrors.length !== 0 && (
|
{displayableErrors.length !== 0 && (
|
||||||
<span
|
<FieldErrors
|
||||||
id={`input-error-${attribute.name}${index === 0 ? "" : `-${index + 1}`}`}
|
attribute={attribute}
|
||||||
className={getClassName("kcInputErrorMessageClass")}
|
index={index}
|
||||||
style={{
|
getClassName={getClassName}
|
||||||
"position": displayableErrors.length === 1 ? "absolute" : undefined
|
displayableErrors={displayableErrors}
|
||||||
}}
|
/>
|
||||||
aria-live="polite"
|
|
||||||
>
|
|
||||||
{displayableErrors.map(({ errorMessage }, i, arr) => (
|
|
||||||
<>
|
|
||||||
<span key={i}>{errorMessage}</span>
|
|
||||||
{arr.length - 1 !== i && <br />}
|
|
||||||
</>
|
|
||||||
))}
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
{attribute.annotations.inputHelperTextAfter !== undefined && index === 0 && (
|
{attribute.annotations.inputHelperTextAfter !== undefined && index === 0 && (
|
||||||
<div
|
<div
|
||||||
@ -338,6 +328,33 @@ function GroupLabel(props: {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function FieldErrors(props: {
|
||||||
|
attribute: Attribute;
|
||||||
|
index: number;
|
||||||
|
getClassName: UserProfileFormFieldsProps["getClassName"];
|
||||||
|
displayableErrors: FormFieldError[];
|
||||||
|
}) {
|
||||||
|
const { attribute, index, getClassName, displayableErrors } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
id={`input-error-${attribute.name}${index === 0 ? "" : `-${index + 1}`}`}
|
||||||
|
className={getClassName("kcInputErrorMessageClass")}
|
||||||
|
style={{
|
||||||
|
"position": displayableErrors.length === 1 ? "absolute" : undefined
|
||||||
|
}}
|
||||||
|
aria-live="polite"
|
||||||
|
>
|
||||||
|
{displayableErrors.map(({ errorMessage }, i, arr) => (
|
||||||
|
<>
|
||||||
|
<span key={i}>{errorMessage}</span>
|
||||||
|
{arr.length - 1 !== i && <br />}
|
||||||
|
</>
|
||||||
|
))}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function AddRemoveButtonsMultiValuedAttribute(props: {
|
function AddRemoveButtonsMultiValuedAttribute(props: {
|
||||||
formFieldStates: FormFieldState[];
|
formFieldStates: FormFieldState[];
|
||||||
attribute: Attribute;
|
attribute: Attribute;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user