From a2bdfab9c5f69d4d371d263fd171c7dac0eb2ccb Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Thu, 11 May 2023 18:17:24 +0200 Subject: [PATCH] added min length > 0 check to required (#20234) fixes: #20096 --- js/apps/admin-ui/src/user/UserProfileFields.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/js/apps/admin-ui/src/user/UserProfileFields.tsx b/js/apps/admin-ui/src/user/UserProfileFields.tsx index 66532e7749..72fecaa11f 100644 --- a/js/apps/admin-ui/src/user/UserProfileFields.tsx +++ b/js/apps/admin-ui/src/user/UserProfileFields.tsx @@ -1,7 +1,4 @@ -import type { - UserProfileAttribute, - UserProfileAttributeRequired, -} from "@keycloak/keycloak-admin-client/lib/defs/userProfileConfig"; +import type { UserProfileAttribute } from "@keycloak/keycloak-admin-client/lib/defs/userProfileConfig"; import { Form, FormGroup, @@ -92,8 +89,9 @@ const FormField = ({ attribute, roles }: FormFieldProps) => { const isRootAttribute = (attr?: string) => attr && ROOT_ATTRIBUTES.includes(attr); - const isRequired = (required: UserProfileAttributeRequired | undefined) => - Object.keys(required || {}).length !== 0; + const isRequired = (attribute: UserProfileAttribute) => + Object.keys(attribute.required || {}).length !== 0 || + ((attribute.validations?.length?.min as number) || 0) > 0; const fieldName = (attribute: UserProfileAttribute) => `${isRootAttribute(attribute.name) ? "" : "attributes."}${attribute.name}`; @@ -107,7 +105,7 @@ const FormField = ({ attribute, roles }: FormFieldProps) => { : attribute.displayName) || attribute.name } fieldId={attribute.name} - isRequired={isRequired(attribute.required)} + isRequired={isRequired(attribute)} validated={errors.username ? "error" : "default"} helperTextInvalid={t("common:required")} >