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.

Watcher for errors computed property does not work to be able to $emit if the input is valid or not

See original GitHub issue

Versions:

  • VueJs:“^2.5.16”
  • Vee-Validate: “^2.1.0-beta.1”

Description:

I am trying to implement a custom input component that can be reused with a variety of props. The problem arises when i want to emit if the input is valid or not. The problem is, from what i can understand, that the errors computed property is refreshed in next tick. For that reason, when the @input or @blur event are emitted is still populated with the old validations and if it is the first event then errors property is not populated at all.

The best solution would be to watch the errors computed property and emit if the input is valid or not when needed but it does not trigger. The fields computed property can be watched but it does not update if it is not actually used somewhere in the component.

Can i get i little help whit this?

This is a snippet of the implementation

<template>
...
 <input
          class="form-control"
          :value="value"
          :placeholder="placeholder"
          @input="onEvent"
          @blur="onEvent"
          v-validate="validations"
          :type="type"
          :disabled="disabled"
          :name="name"
          :data-vv-as="alias">
...
</template>
<script>
...
    watch: {
      errors: function (errorsNew) {
        console.log('errors watch',errorsNew)
      },
      fields: function (fieldsNew) {
        console.log('fields watch',fieldsNew)
      },
    },
...
</script>

Steps To Reproduce:

I added a working simplified version for clarification https://codesandbox.io/s/4q8vonzjp9 #

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
logaretmcommented, Jun 22, 2018

I updated your example with the solution I proposed, cheers.

https://codesandbox.io/s/k95nq798ro

0reactions
fessacchiottocommented, Dec 13, 2018

Thank you. Very useful answer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Watcher for errors computed property does not work to be able ...
The best solution would be to watch the errors computed property and emit if the input is valid or not when needed but...
Read more >
How can i access the errors computed property on custom ...
The best idea i got is to watch the errors computed property and emit an event when a change occurs whit the errors...
Read more >
Properties | Laravel Livewire
Public properties in Livewire are automatically made available to the view. No need to explicitly pass them into the view (although you can...
Read more >
How to use Vue 3 with TypeScript - LogRocket Blog
In this tutorial, we'll demonstrate how to build a Vue app completely in TypeScript. We'll highlight some of the benefits of using TypeScript ......
Read more >
Watchers | Vue.js
Computed properties allow us to declaratively compute derived values. However, there are cases where we need to perform "side effects" in reaction to...
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