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): provide connectWithPath in the change validator and onBlurValidator #3895

Merged
merged 4 commits into from
Sep 6, 2024

Conversation

tujoworker
Copy link
Member

@tujoworker tujoworker commented Sep 4, 2024

This feature allows a validator for a field to connect to another data path. Changes to the data path value will be reflected in a rerender of the validator. But only if the validator is actually in use. This can be controlled with field properties, such as validateUnchanged etc.

Good to know: Why do validators not rerender on every data change? Because field A should not emit the validator of field B. It can be used for various cases, such as backend requests.

But with the new feature called connectWithPath you as a dev get the possibility to control this in a fine granted way.

Quick examples:

import { Form, Field } from '@dnb/eufemia/extensions/forms'

const validator = (value, { connectWithPath }) => {
  const { getValue } = connectWithPath('/myReference')
  const amount = getValue()
  if (amount >= value) {
    return new Error(`The amount should be greater than ${amount}`)
  }
}

render(
  <Form.Handler>
    <Field.Number path="/myReference" defaultValue={2} />

    <Field.Number
      path="/withValidator"
      defaultValue={2}
      validator={validator} // NB: You may use "onBlurValidator" depending on use case.

      //
    />
  </Form.Handler>,
)

Copy link

vercel bot commented Sep 4, 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 Sep 6, 2024 7:07am

Copy link

codesandbox-ci bot commented Sep 4, 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.

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.

I added a few minor commits, hopefully improving the docs a bit.
Looks good🍦

@tujoworker tujoworker force-pushed the fix/refresh-validator-on-rerender branch 2 times, most recently from d752382 to d5037d8 Compare September 4, 2024 09:42
@tujoworker tujoworker force-pushed the fix/refresh-validator-on-rerender branch from 8fc4914 to 9a09a0d Compare September 5, 2024 20:22
@tujoworker tujoworker force-pushed the fix/refresh-validator-on-rerender branch from 0569baa to 09031fc Compare September 5, 2024 21:33
@tujoworker tujoworker force-pushed the fix/refresh-validator-on-rerender branch 2 times, most recently from ca5657b to b162d97 Compare September 6, 2024 04:40
@tujoworker tujoworker changed the title fix(Forms): provide connectWithPath in validator and onBlurValidator fix(Forms): provide connectWithPath and refresh in the change validator and onBlurValidator Sep 6, 2024
@tujoworker tujoworker force-pushed the fix/refresh-validator-on-rerender branch from b162d97 to bdc09c9 Compare September 6, 2024 05:17
@tujoworker tujoworker changed the title fix(Forms): provide connectWithPath and refresh in the change validator and onBlurValidator fix(Forms): provide connectWithPath in the change validator and onBlurValidator Sep 6, 2024
@tujoworker tujoworker force-pushed the fix/refresh-validator-on-rerender branch from 8749e3d to 5d52b69 Compare September 6, 2024 06:58
@tujoworker tujoworker merged commit f4cf06f into main Sep 6, 2024
10 checks passed
@tujoworker tujoworker deleted the fix/refresh-validator-on-rerender branch September 6, 2024 11:09
tujoworker pushed a commit that referenced this pull request Sep 10, 2024
## [10.47.0](v10.46.0...v10.47.0) (2024-09-10)

### 📝 Documentation

* add component translations table to properties docs ([#3902](#3902)) ([66dd12e](66dd12e))
* **useTheme:** updates docs to match TS type definitions ([#3901](#3901)) ([52aaab3](52aaab3))

### ✨ Features

* **Button:** rewise documented `title` prop with aria-label documentation ([#3863](#3863)) ([ea444c0](ea444c0))
* **CopyOnClick:** adds copyContent prop ([e5a91b6](e5a91b6))
* **countries:** Added missing countries from ISO 3166 [#3894](#3894) ([2992084](2992084))
* **countries:** Added missing countries from ISO 3166 [#3894](#3894) ([#3899](#3899)) ([ada0e92](ada0e92))
* **Forms:** extend validations in `Field.NationalIdentityNumber` ([#3888](#3888)) ([50cc26b](50cc26b))
* **Forms:** make it possible to reuse and extend internal validators ([#3908](#3908)) ([7c97bf5](7c97bf5))
* **Forms:** provide `connectWithPath` in the validator and onBlurValidator to get values from other fields/paths ([#3895](#3895)) ([f4cf06f](f4cf06f))
* **Value.Date:** adds numeric variant ([#3907](#3907)) ([b03e199](b03e199))

### 🐛 Bug Fixes

* **Accordion:** deprecate (rename) expandBehaviour in favor of expandBehavior ([#3905](#3905)) ([76143b0](76143b0))
* **Breakpoint:** ensure matching breakpoint ranges in mixins with docs & hooks ([#3896](#3896)) ([260fcaf](260fcaf))
* **Flex:** enhance handling of React fragments ([#3892](#3892)) ([156c805](156c805))
* **Forms:** enhance cleanup routine of fields ([#3885](#3885)) ([388e0b2](388e0b2)), closes [#3877](#3877)
* **Forms:** ensure label supports HTML formatting ([#3911](#3911)) ([227569c](227569c))
* **Forms:** ensure labels do update when they change (async fields) ([#3910](#3910)) ([bc40449](bc40449))
* **Forms:** warn on value prop usage on fields inside iterate with itemPath ([#3886](#3886)) ([116820d](116820d)), closes [#3877](#3877) [#3882](#3882)
* **LabelDescription:** nothing was returned ([#3898](#3898)) ([3452855](3452855))
@tujoworker
Copy link
Member Author

🎉 This PR is included in version 10.47.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.

4 participants