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.

Pass errors to custom input components

See original GitHub issue

Versions:

  • VueJs: 2.1.0
  • Vee-Validate: 2.0

Description:

In the documentation section ‘Component Validation’, one has to pass the errors as attributes to the custom input component:

<custom-input v-validate="'required|email'" data-vv-value-path="innerValue" data-vv-name="custom" label="Email" :has-error="errors.has('custom')"></custom-input>

This can get quite verbose if one wants to also have the error message.

Would it be reasonable to have the errors passed directly to the component ?

Steps To Reproduce:

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
erezmuscommented, Jan 28, 2017

I found a simple way around the problem. I simply pass the validation rules as a prop named ‘validation’

FormText.vue

<template>
  <div class="form-group row" :class="{ 'has-danger' : errors.has(name) }">
    <label class="col-sm-3 col-form-label form-control-label" :for="name">{{ label }}</label>
    <div class="col-sm-9">
      <input type="text" :id="name" :name="name" v-bind:value="value" v-validate="validation" v-on:input="onInput" :placeholder="placeholder ? placeholder : name" :readonly="readonly">
      <div class="form-control-feedback" v-if="errors.has(name)">{{ errors.first(name) }}</div>
    </div>
  </div>
</template>

<script>
export default {
  props: ['label', 'value', 'name', 'placeholder', 'readonly', 'validation'],
  methods: {
    onInput (event) {
      this.$emit('input', event.target.value)
    }
  }
}
</script>

In the parent component:

//
<form-text label="Email" name="email" v-model="email" validation="'required|email'"></form-text>
//

This seems to do the trick

0reactions
lysed-abcommented, Sep 2, 2018

this certainly isn’t working

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building reusable form input component with error handling in ...
In this article I have used reactstrap for design and you will come to know how to make common form input component and...
Read more >
Custom input component has required error even after being ...
I've created a custom input component by implementing the ControlValueAccessor interface. Then, I put it on a form with required validation by ...
Read more >
REACT NATIVE CUSTOM INPUT AND INPUT VALIDATION
Hi, guys in this video we will look at custom input, input validation, and user authentication in react native.Please if you like this...
Read more >
Lesson 15: Handling Error Messages with a Custom Component
We will be creating a custom component that we will pass the FormControl into, and it will automatically display any necessary errors for...
Read more >
Error handling | Vue Formulate ⚡️ The easiest way to build ...
We already know from the inputs documentation that there are error and errors props available on all input elements. ... These error props...
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