Skip to content

Commit

Permalink
Fix form label ordering issue (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
katybaulch authored Dec 23, 2024
1 parent 838ea7a commit a1226a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 1 addition & 6 deletions src/components/forms/DynamicMetadataFields.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormControl, FormErrorMessage, FormHelperText } from '@chakra-ui/react'
import { FormControl, FormErrorMessage } from '@chakra-ui/react'
import { Control, FieldErrors, FieldValues, Path } from 'react-hook-form'
import { FieldType } from '@/interfaces/Metadata'
import { formatFieldLabel } from '@/utils/metadataUtils'
Expand Down Expand Up @@ -92,11 +92,6 @@ export const DynamicMetadataFields = <T extends FieldValues>({

return (
<FormControl isInvalid={!!errors[fieldKey]} mb={4} isRequired={isRequired}>
{fieldType === FieldType.MULTI_SELECT && (
<FormHelperText mb={2}>
You are able to search and can select multiple options
</FormHelperText>
)}
{renderField()}
<FormErrorMessage>
{errors[fieldKey] && `${fieldKey} is required`}
Expand Down
12 changes: 11 additions & 1 deletion src/components/forms/fields/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
import { Select as CRSelect } from 'chakra-react-select'
import { chakraStylesSelect } from '@/styles/chakra'
import { generateSelectOptions } from '@/utils/metadataUtils'
import { FormControl, FormLabel, FormErrorMessage } from '@chakra-ui/react'
import {
FormControl,
FormLabel,
FormErrorMessage,
FormHelperText,
} from '@chakra-ui/react'
import { IChakraSelect } from '@/interfaces'

type TProps<T extends FieldValues> = {
Expand Down Expand Up @@ -62,6 +67,11 @@ export const SelectField = <T extends FieldValues>({
render={({ field, fieldState: { error } }) => (
<FormControl isInvalid={!!error} isRequired={isRequired}>
{label && <FormLabel>{label}</FormLabel>}
{isMulti && (
<FormHelperText mb={2}>
You are able to search and can select multiple options
</FormHelperText>
)}
<CRSelect
chakraStyles={chakraStylesSelect}
isClearable={isClearable}
Expand Down

0 comments on commit a1226a8

Please sign in to comment.