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

Adding global validation messages overrides all default messages #42

Closed
joneath opened this issue Jan 25, 2022 · 1 comment
Closed

Adding global validation messages overrides all default messages #42

joneath opened this issue Jan 25, 2022 · 1 comment
Assignees
Labels
🐛 bug Verified bug by team 🚀 release-ready Feature or fix is complete and on an upcoming release branch

Comments

@joneath
Copy link

joneath commented Jan 25, 2022

Describe the bug
When following the docs at https://docs.formkit.com/essentials/validation under the headline "Global validation message" to add a custom validation message for a built in or custom validation it will override all the default validation messages for the en locale. This is because the locales.en object is being fully overridden and is not merging with the default ui or validation objects. The current workaround is to import the en locale and extend when defining custom validation messages

import { en } from '@formkit/i18n'

const app = createApp(App).use(
    FormKitPlugin,
    defaultFormKitConfig({
      locales: {
        en: {
          ...en,
          validation: {
            ...en.validation,
            ...customFormKitValidationMessages,
          },
        },
      },
    })
  )

Reproduction

  1. Have a <FormKit /> input with required validation.
  2. Trigger validation and message should read as: ${input.name} is required.
  3. In FormKitPlugin setup include the defaultFormKitConfig and define the following object:
locales: {
  en: {
    validation: {
      foo() { return 'bar' }
    }
  }
}
  1. Reload browser and trigger validation. You will see the following message: This field is not valid.

Desktop (please complete the following information):

  • OS: macOS Monterey 12.1
  • Browser: Chrome
  • Version 97
@justin-schroeder
Copy link
Member

Mmmmm. Correct you are @joneath — definitely need to fix this for beta.1

Appreciate the bug solid bug report 👍

@justin-schroeder justin-schroeder self-assigned this Jan 25, 2022
@justin-schroeder justin-schroeder added the 🐛 bug Verified bug by team label Jan 25, 2022
@justin-schroeder justin-schroeder added the 🚀 release-ready Feature or fix is complete and on an upcoming release branch label Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Verified bug by team 🚀 release-ready Feature or fix is complete and on an upcoming release branch
Projects
None yet
Development

No branches or pull requests

2 participants