-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bedre validering av fravær og arbeidssituasjon
- Loading branch information
1 parent
0de0707
commit 242f994
Showing
4 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...mmon-formik-ds/src/components/formik-standalone-validation/FormikStandaloneValidation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Fieldset, FieldsetProps } from '@navikt/ds-react'; | ||
import React from 'react'; | ||
import { FastField, Field, FieldProps } from 'formik'; | ||
import { TypedFormInputValidationProps, UseFastFieldProps } from '../../types'; | ||
import { getErrorPropForFormikInput } from '../../utils/typedFormErrorUtils'; | ||
import { TypedFormikFormContext } from '../typed-formik-form/TypedFormikForm'; | ||
|
||
interface OwnProps<FieldName> extends Omit<FieldsetProps, 'name'> { | ||
name: FieldName; | ||
} | ||
|
||
export type FormikInputGroupProps<ErrorType, FieldName> = OwnProps<FieldName> & | ||
TypedFormInputValidationProps<FieldName, ErrorType> & | ||
UseFastFieldProps; | ||
|
||
function FormikInputGroup<ErrorType, FieldName>({ | ||
name, | ||
error, | ||
id, | ||
validate, | ||
useFastField, | ||
...restProps | ||
}: FormikInputGroupProps<ErrorType, FieldName>) { | ||
const context = React.useContext(TypedFormikFormContext); | ||
const FieldComponent = useFastField ? FastField : Field; | ||
return ( | ||
<FieldComponent validate={validate ? (value: any) => validate(value, name) : undefined} name={name}> | ||
{({ field, form }: FieldProps) => { | ||
return ( | ||
<Fieldset | ||
{...restProps} | ||
error={getErrorPropForFormikInput({ field, form, context, error })} | ||
id={id} | ||
tabIndex={id ? -1 : undefined} | ||
/> | ||
); | ||
}} | ||
</FieldComponent> | ||
); | ||
} | ||
export default FormikInputGroup; |