Vee-validate: Differents messages for required validator

Created on 18 May 2017  Â·  5Comments  Â·  Source: logaretm/vee-validate

Versions:

  • VueJs: 2.2.6
  • Vee-Validate: 2.0.0-rc.3

Description:

I try to add two differents messages for the same validator (required)

For example :

  • Required on input name : "Name is empty"
  • Required on input email : "Please add an email on field"

Do you have any suggestions ?

Steps To Reproduce:

✨ enhancement

Most helpful comment

I just added support for it, here is an example for it:

    this.$validator.dictionary.merge({
      en: {
        custom: {
          email: {
            required: 'Your email is emoty'
          },
          name: {
            required: () => 'Your name is empty'
          }
        }
      }
    })

You need to merge the custom messages object which contains keys of the fields names as properties, each property value is an object containing keys for each rule you would like to customize the message for. You only need to provide messages for the rules you would like to be replaced. It will fallback to the default messages included.

Also messages can be either strings or functions.

Note that you should merge the messages as soon as your app needs them, for example at the entry point or plugin installation.

All 5 comments

Currently its not supported to provide different messages for different fields, I will try to look into it tho.

I support this feature request - would love it to work as laravel does.
Thanks again for a great library!

I just added support for it, here is an example for it:

    this.$validator.dictionary.merge({
      en: {
        custom: {
          email: {
            required: 'Your email is emoty'
          },
          name: {
            required: () => 'Your name is empty'
          }
        }
      }
    })

You need to merge the custom messages object which contains keys of the fields names as properties, each property value is an object containing keys for each rule you would like to customize the message for. You only need to provide messages for the rules you would like to be replaced. It will fallback to the default messages included.

Also messages can be either strings or functions.

Note that you should merge the messages as soon as your app needs them, for example at the entry point or plugin installation.

This doesn't work for me
Do you have an example with html files

Thanks

It is not released yet, you can't use until the next RC release.

Was this page helpful?
0 / 5 - 0 ratings