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

fix(forms): enhance Field.Name validation rule #3849

Merged
merged 3 commits into from
Aug 21, 2024
Merged

Conversation

tujoworker
Copy link
Member

@tujoworker tujoworker commented Aug 20, 2024

const validNames = [
  'Ole',
  'Anne-Marie',
  'Hans Christian',
  'Åse',
  'Müller',
  'García-López',
  'Frédéric-Jean',
]

const invalidNames = [
  'Ole1',
  'Hans  Christian',
  'Anne--Marie',
  '@nna',
  'Ole--',
  'Liv-',
  ' Martin',
  'Anders ',
]

it.each(validNames)('Valid name: %s', (name) => {
  render(<Field.Name validateInitially value={name} />)
  expect(screen.queryByRole('alert')).not.toBeInTheDocument()
})

it.each(invalidNames)('Invalid name: %s', (name) => {
  render(<Field.Name validateInitially value={name} />)
  expect(screen.queryByRole('alert')).toBeInTheDocument()
  expect(screen.queryByRole('alert')).toHaveTextContent(
    nb.Field.errorPattern
  )
})

Copy link

vercel bot commented Aug 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eufemia ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 20, 2024 7:17pm

Copy link

codesandbox-ci bot commented Aug 20, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@tujoworker tujoworker force-pushed the fix/name-validation branch from 13e4682 to 1c24fcd Compare August 20, 2024 12:37
Copy link
Contributor

@langz langz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me 👍

I don't 100% understand the validation rule, or why we want/need validation rules for names. Does it exist a rule for how a name could look like? Is it the government who decides this? Is it different from country to country? Or perhaps its DNB who wants these rules for names? 🤔

@tujoworker
Copy link
Member Author

We had a very weak check. The new regex is still not very strict, but as you can see in the tests, it takes care of obvious wrongly written names.
I don't think there is the perfect validation for names. But I think this brings us a long way. And yes, the change is made from feedback by the Trident team. That said, they used a much stricter regex.

@langz
Copy link
Contributor

langz commented Aug 21, 2024

We had a very weak check. The new regex is still not very strict, but as you can see in the tests, it takes care of obvious wrongly written names.

I don't think there is the perfect validation for names. But I think this brings us a long way. And yes, the change is made from feedback by the Trident team. That said, they used a much stricter regex.

Thanks for the explanation🫡

@tujoworker tujoworker merged commit 9c9142d into main Aug 21, 2024
10 checks passed
@tujoworker tujoworker deleted the fix/name-validation branch August 21, 2024 11:02
tujoworker pushed a commit that referenced this pull request Aug 26, 2024
## [10.45.0](v10.44.0...v10.45.0) (2024-08-26)

### 📝 Documentation

* **Upload:** adds `false` as a file max size type ([#3846](#3846)) ([8747e74](8747e74))

### 🐛 Bug Fixes

* **forms:** enhance `Field.Name` validation rule ([#3849](#3849)) ([9c9142d](9c9142d))
* **forms:** ensure `Iterate.Array` can handle an array given in the data context ([#3842](#3842)) ([263f4c7](263f4c7)), closes [#3759](#3759)
* **forms:** ensure `Section.EditContainer` cancel restores data when path is given ([#3853](#3853)) ([eabc583](eabc583)), closes [#3797](#3797)
* **forms:** ensure pressing enter in an input field inside Wizard does trigger next step ([#3852](#3852)) ([fd35828](fd35828))
* **forms:** make `Form.Isolation`s data flow "from outside" stricter ([#3847](#3847)) ([977962b](977962b)), closes [#3844](#3844)
* **forms:** validate fields inside `Iterate.EditContainer` when done button is pressed ([#3850](#3850)) ([2a2272e](2a2272e))
* **forms:** validate fields inside `Section.EditContainer` when done button is pressed ([#3851](#3851)) ([1c34980](1c34980))
* **useTheme:** define the return type of `null` as a possible return ([#3861](#3861)) ([8d0cf61](8d0cf61))

### ✨ Features

* **forms:** add `inheritLabel` prop to value components ([#3858](#3858)) ([01e0976](01e0976))
* **forms:** add `Iterate.PushContainer` to support an "initially open" container ([#3843](#3843)) ([0fe23a9](0fe23a9))
* **forms:** add `Value.ArraySelection` component ([#3854](#3854)) ([bc55cc2](bc55cc2))
* **forms:** add `Value.Selection` component ([#3857](#3857)) ([7432986](7432986))
* **forms:** add support for `{itemNr}` to the iterate container title + add `useItem` hook ([#3848](#3848)) ([0d50272](0d50272))
* **Upload:** define max file size for file type ([#3859](#3859)) ([13fc1a8](13fc1a8))
@tujoworker
Copy link
Member Author

🎉 This PR is included in version 10.45.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants