Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am trying to use Vue.js. My service returns ajax response when request is not validated successfully (400). The response contains invalid data field details which I want to use to mark input fields with css 'invalid' class.

The vue.js form is

 <validator name="validation">
      <form novalidate>
        <div class="form-group">
          <input 
          id="username"
          type="text" 
          class="form-control"
          placeholder="Enter your username"
          v-model="credentials.username"
          v-validate:credentials.username="['required']"

          >
        </div>
        <div class="form-group">
          <input
          id="password"
          type="password"
          class="form-control"
          placeholder="Enter your password"
          v-model="credentials.password"
          v-validate:credentials.password="['required']"
          >
        </div>
      <div class="errors">
        <validator-errors :validation="$validation"></validator-errors>
      </div>
        <button class="btn btn-primary"  @click="submit()">Access</button>
      </form>
      </validator>

And bad request response contains data:

{
    "username": [{
        "memberNames": ["UserName"],
        "errorMessage": "Field 'User Name' can't be empty."
    }],
    "password": [{
        "memberNames": ["Password"],
        "errorMessage": "Field 'Password' can't be empty."
    }]
}
share|improve this question
    
Please clarify your question. Is the 400 status spected? what is that code? your data? where do you want to add the invalid class? what's actually your question? – Yerko Palma Feb 22 at 12:14
    
When validation fails backend returns http statu code 400 with json serialized validation details. After that I would like to attach css class to inputs which are not validated successfully. – marcinn Feb 22 at 12:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.