add validation for req fields
This commit is contained in:
parent
7ba357c223
commit
346e92aa8b
4 changed files with 39 additions and 14 deletions
|
@ -10,7 +10,7 @@ import {
|
|||
SelectOption,
|
||||
SelectVariant,
|
||||
TextInput,
|
||||
ValidatedOptions
|
||||
ValidatedOptions,
|
||||
} from "@patternfly/react-core";
|
||||
import { convertFormValuesToObject, convertToFormValues } from "../../../util";
|
||||
import type ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation";
|
||||
|
@ -159,9 +159,11 @@ export const LdapMapperDetails = () => {
|
|||
id="kc-ldap-mapper-name"
|
||||
data-testid="ldap-mapper-name"
|
||||
name="name"
|
||||
ref={form.register({ required: true})}
|
||||
ref={form.register({ required: true })}
|
||||
validated={
|
||||
form.errors.name ? ValidatedOptions.error : ValidatedOptions.default
|
||||
form.errors.name
|
||||
? ValidatedOptions.error
|
||||
: ValidatedOptions.default
|
||||
}
|
||||
/>
|
||||
<TextInput
|
||||
|
|
|
@ -36,7 +36,9 @@ export const LdapMapperHardcodedLdapGroup = ({
|
|||
name="config.group[0]"
|
||||
ref={form.register({ required: true })}
|
||||
validated={
|
||||
form.errors.config && form.errors.config.group ? ValidatedOptions.error : ValidatedOptions.default
|
||||
form.errors.config && form.errors.config.group
|
||||
? ValidatedOptions.error
|
||||
: ValidatedOptions.default
|
||||
}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import { Button, FormGroup, TextInput } from "@patternfly/react-core";
|
||||
import {
|
||||
Button,
|
||||
FormGroup,
|
||||
TextInput,
|
||||
ValidatedOptions,
|
||||
} from "@patternfly/react-core";
|
||||
import React, { useState } from "react";
|
||||
import { HelpItem } from "../../../components/help-enabler/HelpItem";
|
||||
import type { UseFormMethods } from "react-hook-form";
|
||||
|
@ -71,7 +76,12 @@ export const LdapMapperHardcodedLdapRole = ({
|
|||
id="kc-role"
|
||||
data-testid="role"
|
||||
name="config.role[0]"
|
||||
ref={form.register}
|
||||
ref={form.register({ required: true })}
|
||||
validated={
|
||||
form.errors.config && form.errors.config.role
|
||||
? ValidatedOptions.error
|
||||
: ValidatedOptions.default
|
||||
}
|
||||
/>
|
||||
<Button
|
||||
className="keycloak__user-federation__assign-role-btn"
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
SelectVariant,
|
||||
Switch,
|
||||
TextInput,
|
||||
ValidatedOptions,
|
||||
} from "@patternfly/react-core";
|
||||
import React, { useState } from "react";
|
||||
import { HelpItem } from "../../../components/help-enabler/HelpItem";
|
||||
|
@ -77,7 +78,16 @@ export const LdapMapperRoleGroup = ({
|
|||
id="kc-ldap-dn"
|
||||
data-testid="ldap-dn"
|
||||
name={isRole ? "config.roles-dn[0]" : "config.groups-dn[0]"}
|
||||
ref={form.register}
|
||||
ref={form.register({ required: true })}
|
||||
validated={
|
||||
isRole
|
||||
? form.errors.config && form.errors.config["roles-dn"]
|
||||
? ValidatedOptions.error
|
||||
: ValidatedOptions.default
|
||||
: form.errors.config && form.errors.config["groups-dn"]
|
||||
? ValidatedOptions.error
|
||||
: ValidatedOptions.default
|
||||
}
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup
|
||||
|
@ -297,10 +307,8 @@ export const LdapMapperRoleGroup = ({
|
|||
/>
|
||||
}
|
||||
fieldId="kc-ldap-filter"
|
||||
isRequired
|
||||
>
|
||||
<TextInput
|
||||
isRequired
|
||||
type="text"
|
||||
id="kc-ldap-filter"
|
||||
data-testid="ldap-filter"
|
||||
|
@ -519,10 +527,8 @@ export const LdapMapperRoleGroup = ({
|
|||
/>
|
||||
}
|
||||
fieldId="kc-mapped-attributes"
|
||||
isRequired
|
||||
>
|
||||
<TextInput
|
||||
isRequired
|
||||
type="text"
|
||||
id="kc-mapped-attributes"
|
||||
data-testid="mapped-attributes"
|
||||
|
@ -577,7 +583,12 @@ export const LdapMapperRoleGroup = ({
|
|||
data-testid="path"
|
||||
defaultValue="/"
|
||||
name="config.groups-path[0]"
|
||||
ref={form.register}
|
||||
ref={form.register({ required: true })}
|
||||
validated={
|
||||
form.errors.config && form.errors.config["groups-path"]
|
||||
? ValidatedOptions.error
|
||||
: ValidatedOptions.default
|
||||
}
|
||||
/>
|
||||
</FormGroup>
|
||||
</>
|
||||
|
|
Loading…
Reference in a new issue