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 display an Error Message received by the Rest Api onto a specific field name?

See original GitHub issue

Versions:

  • VueJs: 2.3.3
  • Vee-Validate: 2.0.0-rc.5

Description:

On the Login page, once the this.$validator.validateAll() is called the request goes to the back-end and when the request comes back with a 401 status code I need to display the incorrect username/password error message.

Steps To Reproduce:

This is how the existing cook looks like.

import VeeValidate from 'vee-validate'
Vue.use(VeeValidate)

<input 
                            name="username"
                            v-validate="'required|email'"
                            v-model="vm.username" 
                            autofocus
                            class="input is-medium"
                            v-bind:class="{
                              'is-danger': errors.has('username'),
                              'is-success': !errors.has('username')
                            }"
                            type="email"
                            placeholder="username@eduhours.com"
                          />
                          <span class="icon user">
                            <i class="fa fa-user"></i>
                          </span>

validateBeforeSubmit: function (e) {
      this.$validator.validateAll()
      .then(() => {
        this.onSubmit()
      })
      .catch(() => { })
    }

onSubmit: function () {
  axios.post('auth', json)
  .then()
  .error(error => {
    // when 401 is received I want to add the value to the value to the error bag?
  })
}

Issue Analytics

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

github_iconTop GitHub Comments

9reactions
coderabsolutecommented, Aug 7, 2018

I got it, but for others posting the answer here.

this.errors.add({
      field: 'Item',
      msg: 'The item is expired.'
    });
6reactions
logaretmcommented, Jun 16, 2017

You can use

this.errors.add('credentials', msg);

where msg is the message you want to display, and just add it to the template using:

{{ errors.first('credentials') }}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding And Using REST APIs - Smashing Magazine
You open up Youtube, type “Batman” into a search field, hit enter, and you see a list of videos about Batman. A REST...
Read more >
Working with lists and list items with REST | Microsoft Learn
Property Description Type GroupString Group identifier used for drill‑down feature. string Field Specifies a special field that should be included. string FilterData Data specified by a...
Read more >
JetEngine: How to Show Content with the Help of REST API
The first one is to display the fields directly. In the Source drop-down menu of the Content menu section, choose the “Post/Term/User/Object Data”...
Read more >
Best Practices for REST API Error Handling - Baeldung
The simplest way we handle errors is to respond with an appropriate status code. Here are some common response codes: 400 Bad Request...
Read more >
Error Consuming REST API using Filter Set field Action
From the above response mapping i am willing to set the Submitter values get in JSON response into my form field API Response...
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