add validation for req fields

This commit is contained in:
mfrances 2021-06-09 11:18:09 -04:00
parent 7ba357c223
commit 346e92aa8b
4 changed files with 39 additions and 14 deletions

View file

@ -10,7 +10,7 @@ import {
SelectOption, SelectOption,
SelectVariant, SelectVariant,
TextInput, TextInput,
ValidatedOptions ValidatedOptions,
} from "@patternfly/react-core"; } from "@patternfly/react-core";
import { convertFormValuesToObject, convertToFormValues } from "../../../util"; import { convertFormValuesToObject, convertToFormValues } from "../../../util";
import type ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation"; import type ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation";
@ -159,9 +159,11 @@ export const LdapMapperDetails = () => {
id="kc-ldap-mapper-name" id="kc-ldap-mapper-name"
data-testid="ldap-mapper-name" data-testid="ldap-mapper-name"
name="name" name="name"
ref={form.register({ required: true})} ref={form.register({ required: true })}
validated={ validated={
form.errors.name ? ValidatedOptions.error : ValidatedOptions.default form.errors.name
? ValidatedOptions.error
: ValidatedOptions.default
} }
/> />
<TextInput <TextInput

View file

@ -35,8 +35,10 @@ export const LdapMapperHardcodedLdapGroup = ({
data-testid="mapper-group-fld" data-testid="mapper-group-fld"
name="config.group[0]" name="config.group[0]"
ref={form.register({ required: true })} ref={form.register({ required: true })}
validated={ validated={
form.errors.config && form.errors.config.group ? ValidatedOptions.error : ValidatedOptions.default form.errors.config && form.errors.config.group
? ValidatedOptions.error
: ValidatedOptions.default
} }
/> />
</FormGroup> </FormGroup>

View file

@ -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 React, { useState } from "react";
import { HelpItem } from "../../../components/help-enabler/HelpItem"; import { HelpItem } from "../../../components/help-enabler/HelpItem";
import type { UseFormMethods } from "react-hook-form"; import type { UseFormMethods } from "react-hook-form";
@ -71,7 +76,12 @@ export const LdapMapperHardcodedLdapRole = ({
id="kc-role" id="kc-role"
data-testid="role" data-testid="role"
name="config.role[0]" 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 <Button
className="keycloak__user-federation__assign-role-btn" className="keycloak__user-federation__assign-role-btn"

View file

@ -5,6 +5,7 @@ import {
SelectVariant, SelectVariant,
Switch, Switch,
TextInput, TextInput,
ValidatedOptions,
} from "@patternfly/react-core"; } from "@patternfly/react-core";
import React, { useState } from "react"; import React, { useState } from "react";
import { HelpItem } from "../../../components/help-enabler/HelpItem"; import { HelpItem } from "../../../components/help-enabler/HelpItem";
@ -77,7 +78,16 @@ export const LdapMapperRoleGroup = ({
id="kc-ldap-dn" id="kc-ldap-dn"
data-testid="ldap-dn" data-testid="ldap-dn"
name={isRole ? "config.roles-dn[0]" : "config.groups-dn[0]"} 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>
<FormGroup <FormGroup
@ -297,10 +307,8 @@ export const LdapMapperRoleGroup = ({
/> />
} }
fieldId="kc-ldap-filter" fieldId="kc-ldap-filter"
isRequired
> >
<TextInput <TextInput
isRequired
type="text" type="text"
id="kc-ldap-filter" id="kc-ldap-filter"
data-testid="ldap-filter" data-testid="ldap-filter"
@ -519,10 +527,8 @@ export const LdapMapperRoleGroup = ({
/> />
} }
fieldId="kc-mapped-attributes" fieldId="kc-mapped-attributes"
isRequired
> >
<TextInput <TextInput
isRequired
type="text" type="text"
id="kc-mapped-attributes" id="kc-mapped-attributes"
data-testid="mapped-attributes" data-testid="mapped-attributes"
@ -577,7 +583,12 @@ export const LdapMapperRoleGroup = ({
data-testid="path" data-testid="path"
defaultValue="/" defaultValue="/"
name="config.groups-path[0]" 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> </FormGroup>
</> </>