question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Custom messages per rule and field

See original GitHub issue

Versions:

  • VueJs: 2.5.16
  • Vee-Validate: 2.0.9

Assumptions

  • Vue SSR
  • I have an input component
  • Scoped form

Question:

How would I do the following? I’m trying to make the required message for firstName be:

Please enter your first name.

and for city:

Please enter the city.

Steps To Reproduce:

So far I have:

const dictionary = {
  en: {
    messages: {
      required: (field) => {
        if (field === 'firstName') {
          return `Please enter your ${field}.`
        } else if (field === 'city') {
          return `Please enter the ${field}.`
        }
        return `Please enter a ${field}.`
      },
    },
  },
}

Object.keys(veeRules).forEach(k => Validator.extend(k, veeRules[k]))
Validator.localize('en', veeEn)
Vue.use(VeeValidate, { inject: false, dictionary })

But this doesn’t seem correct.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
logaretmcommented, May 18, 2018

You could assign specific error messages to specific fields:

const dictionary = {
  en: {
    custom: {
      firstName: {
         required: 'Please enter your first name.'
      },
      city: {
        required: 'Please enter the city.'
      }
    }
  }
}

Object.keys(veeRules).forEach(k => Validator.extend(k, veeRules[k]))
Validator.localize('en', veeEn)
Vue.use(VeeValidate, { inject: false, dictionary })
1reaction
g3rdcommented, May 18, 2018

@elujoba I know that you fixed it, but more info is here: https://github.com/baianat/vee-validate/issues/1329

Read more comments on GitHub >

github_iconTop Results From Across the Web

CodeIgniter custom validation errors for each rule per each field
I'm using CodeIngiter 2.1 and I wanna define custom validation errors for each rule per each field. The fields are as follows. array(...
Read more >
How to customize validate rule error messages | Support Center
When I enter numbers in the text field I get the error message "Enter a valid alphabetic value". I want to customize this...
Read more >
How to have a custom message for any required fields
I have created custom object (School) with a custom field (Address) and checked it as required. Now the message is displayed as “Error:...
Read more >
Response Requirements & Validation - Qualtrics
Custom validation is used when you need your respondent to answer a question in a specific way. For example, you may want them...
Read more >
How to show custom error messages without using $validator?
You can't show validation errors for fields that aren't in the $rules. You set a custom message here for the participant_question field. Copy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found