-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(PhoneNumber): handle pattern, schema and validator with country c…
…ode (#3249)
- Loading branch information
1 parent
bc05141
commit ed115d5
Showing
6 changed files
with
129 additions
and
32 deletions.
There are no files selected for viewing
10 changes: 5 additions & 5 deletions
10
...esign-system-portal/src/docs/uilib/extensions/forms/data-value-write-events.mdx
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
| Event | Description | | ||
| ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `onChange` | _(optional)_ Will be called on value changes made by the user, with the new value as argument. | | ||
| `onFocus` | _(optional)_ Will be called when the component gets into focus. Like clicking inside a text input or opening a dropdown. Called with active value as argument. | | ||
| `onBlur` | _(optional)_ Will be called when the component stop being in focus. Like when going to next field, or closing a dropdown. Called with active value as argument. | | ||
| Event | Description | | ||
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `onChange` | _(optional)_ Will be called on value changes made by the user, with the new value e.g. `+47 99999999`. The second parameter is an object: `{ countryCode, phoneNumber }`. | | ||
| `onFocus` | _(optional)_ Will be called when the component gets into focus. Like clicking inside a text input or opening a dropdown. Called with active value as argument. | | ||
| `onBlur` | _(optional)_ Will be called when the component stop being in focus. Like when going to next field, or closing a dropdown. Called with active value as argument. | |
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
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
49 changes: 31 additions & 18 deletions
49
packages/dnb-eufemia/src/extensions/forms/Field/PhoneNumber/stories/PhoneNumber.stories.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 |
---|---|---|
@@ -1,28 +1,41 @@ | ||
import React from 'react' | ||
import { Field } from '../../..' | ||
import { Field, Form } from '../../..' | ||
import { Flex } from '../../../../../components' | ||
|
||
export default { | ||
title: 'Eufemia/Extensions/Forms/PhoneNumber', | ||
} | ||
|
||
const initialData = { phone: '+47 423456789' } | ||
|
||
export function PhoneNumber() { | ||
const [state, update] = React.useState('+47 1') | ||
// const [state, update] = React.useState(undefined) | ||
React.useEffect(() => { | ||
// update('+41 1') | ||
update('+45') | ||
}, []) | ||
const { update } = Form.useData('uniqueId') | ||
|
||
React.useLayoutEffect(() => { | ||
update('/phone', () => '+41 123') | ||
}, [update]) | ||
|
||
return ( | ||
<Field.PhoneNumber | ||
required | ||
pattern="^[49]+" | ||
value={state} | ||
onBlur={console.log} | ||
onFocus={console.log} | ||
onChange={(value) => { | ||
console.log('onChange', value) | ||
update(value) | ||
}} | ||
/> | ||
<Form.Handler id="uniqueId" data={initialData}> | ||
<Flex.Stack> | ||
<Field.PhoneNumber | ||
pattern="((?=\+47)^\+47 [49]\d{7}$)|((?!\+47)^\+\d{2} \d{6})" | ||
// pattern="^\+47 [49]+" | ||
// required | ||
// validateInitially | ||
path="/phone" | ||
onBlur={console.log} | ||
onFocus={console.log} | ||
onChange={(value) => { | ||
console.log('onChange', value) | ||
update('/phone', () => value) | ||
}} | ||
/> | ||
<Field.String label="Shadow" path="/phone" /> | ||
<Form.ButtonRow> | ||
<Form.SubmitButton /> | ||
</Form.ButtonRow> | ||
</Flex.Stack> | ||
</Form.Handler> | ||
) | ||
} |