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.

How to set multiple error messages?

See original GitHub issue

An input box has multiple validation rules, such as required and email, so how can I distinguish between setting prompt characters for them? <input type="text" class="form-control" v-model="form.email" v-validate.disable="'required|email'" data-vv-as="email address" name="email" placeholder="enter email"> I hope that the error prompt of required is “mailbox must be filled”, and the email is “the mailbox format you entered is not correct”.

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
941477276commented, Jul 21, 2018

yes, it does. Thank you very much.But there is also a situation where I have an email input box on multiple pages, and in this way the value of the “name” attribute in my input box has to be different, otherwise the error message will not be correct

//page1:
<input type="text" name="email" v-validate="'required|email'">
//page2:
<input type="text" name="email2" v-validate="'required|email'">
//main.js:
Validator.localize({
  en: {
    custom: {
      email: {
        required: "Please enter your email address",
        email: "Your email does not look right"
      },
      email2: {
        required: "Please enter your email address222222",
        email: "Your email does not look right22222"
      }
    }
  }
});

If I have 10 pages with email input fields, and they all have their own validation rules and corresponding error messages, then I’m not going to define 10 names.So what I’m trying to say is can you define error messages in the page, not in mian.js, because in mian.js the definition can affect the whole world

3reactions
logaretmcommented, Jul 20, 2018

Sorry, was away for a few days.

Thanks for the suggestions and the proposals, I believe this was requested before and I was against it since I don’t like adding too many attrs to the template, it can get ugly really quick.

Instead, use the custom field in the dictionary to set your custom messages, which is very similar to the jquery validator.

Validator.localize({
  en: {
    custom: {
      email: {
        required: 'Please enter your email address',
        email: 'Your email does not look right'
      }
    }
  }
})

Note that it matches the custom field with the name of the field, meaning your field must have the name email in the previous snippet.

Here is an example of it:

https://codesandbox.io/s/rlvk13ln7n

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add multiple error messages inside a custom request?
Inside my custom request, I have a custom rule and it runs multiple conditions. How can I add error messages to each of...
Read more >
How to fix multiple error messages shown in a single line issue
1. Write an activity and call Page-Set-Messages method. Then reference Message rule by RUF. · 2. Here are the two Message rules that...
Read more >
How do I account for multiple error messages with a single Try ...
You can check for multiple errors using the following method: try: ... except (NameError, TypeError) as error: print(error).
Read more >
React Hook Form - ErrorMessage: multiple error messages
TemplateReact Hook Form - ErrorMessage · Environmentcreate-react-app.
Read more >
Error Messages: Examples, Best Practices & Common Mistakes
How to write good error messages: The 4 H's · 1. Write for humans (be understandable) · 2. Make sure the message is...
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