Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(OrganizationNumber): adds docs about validation #4122

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const ValidationExtendValidator = () => {
return (
<ComponentBox>
{() => {
const firstNumIs1Validator = (value: string) => {
const firstDigitIs1Validator = (value: string) => {
if (value.substring(0, 1) !== '1') {
return new Error('My error')
}
Expand All @@ -125,7 +125,7 @@ export const ValidationExtendValidator = () => {
const myValidator = (value, { validators }) => {
const { organizationNumberValidator } = validators

return [organizationNumberValidator, firstNumIs1Validator]
return [organizationNumberValidator, firstDigitIs1Validator]
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ import { OrganizationNumberProperties } from '@dnb/eufemia/src/extensions/forms/

<PropertiesTable props={fieldProperties} omit={['onBlurValidator']} />

## Validators

### Internal validators exposed

`Field.OrganizationNumber` expose the `organizationNumberValidator` validator through its `validator` and `onBlurValidator` property.
The `organizationNumberValidator` validator, validates if the organization number provided is a [Norwegian organization number](https://www.brreg.no/om-oss/registrene-vare/om-enhetsregisteret/organisasjonsnummeret/) or not.

## Translations

<TranslationsTable localeKey={['OrganizationNumber', 'Field']} />
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const OrganizationNumberProperties: PropertiesTableProps = {
status: 'optional',
},
onBlurValidator: {
doc: 'Custom validator function that is triggered when the user leaves a field (e.g., blurring a text input or closing a dropdown). The function can be either asynchronous or synchronous. The first parameter is the value, and the second parameter returns an object containing { errorMessages, connectWithPath, validators }. Defaults to organization number validation, using `organizationNumberValidator`.',
doc: 'Custom validator function that is triggered when the user leaves a field (e.g., blurring a text input or closing a dropdown). The function can be either asynchronous or synchronous. The first parameter is the value, and the second parameter returns an object containing { errorMessages, connectWithPath, validators }. Defaults to organization number validation, using `organizationNumberValidator`. Can be disabled using `false`.',
type: 'function',
status: 'optional',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ describe('Field.OrganizationNumber', () => {
const invalidOrgNum = ['123456789', '148623907', '987654321']
const invalidOrgNumTooShort = ['123', '321', '123123', '321321']

const firstNumIs1Validator = (value: string) => {
const firstDigitIs1Validator = (value: string) => {
if (value.substring(0, 1) !== '1') {
return new Error('My error')
}
Expand All @@ -444,7 +444,7 @@ describe('Field.OrganizationNumber', () => {
const customValidator: Validator<string> = (value, { validators }) => {
const { organizationNumberValidator } = validators

return [organizationNumberValidator, firstNumIs1Validator]
return [organizationNumberValidator, firstDigitIs1Validator]
}

it.each(validOrgNumStartingWith1)(
Expand Down
Loading