Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v-validate:computedProperty does not validate properly on validateAll() #423

Closed
xxRockOnxx opened this issue Apr 11, 2017 · 6 comments
Closed
Labels
✨ enhancement a "nice to have" feature

Comments

@xxRockOnxx
Copy link

xxRockOnxx commented Apr 11, 2017

Versions:

  • VueJs: 2
  • Vee-Validate: 2

Description:

I have a custom component, and I use v-validate:computedProperty instead of receiving the one that the component emit. It emits an object.

It's fine when validates when changed. I have a custom rule and I checked why it fails. Rule is something like:

  const time = {
    getMessage (field) {
      return `The ${field} must be a valid time.`
    },

    validate (value) {
      console.log(value)
      return moment(value, 'HH:mm').isValid()
    }
  }

The console.log shows that computedProperty value on change/input. But when it's validated using validateAll() it shows the object being passed by the component.

Steps To Reproduce:

1 - have a component emit('input', {})
2 - v-validate:computedValue={ rules: rules.yourRules }
3 - computedValue() { return (!this.a || !this.b) '' : this.a + this.b }
4 - validateAll()

EDIT:

Good thing validateAll accepts what to validate. I use it currently as a workaround.

@logaretm logaretm added the ✨ enhancement a "nice to have" feature label Apr 11, 2017
@logaretm
Copy link
Owner

Are you binding the input value with the computed property?

<input type="text" :value="computedProp" v-validate:computedProp="rules">

if not, do you mind trying and report the results? thanks.

@xxRockOnxx
Copy link
Author

I use v-model

The custom component accepts an object instead of a regular String. It's the vue2-timepicker btw.

<vue-timepicker v-model="myModel" v-validate:computedProp="{ rules: rules }" >

That's why I needed to validate the computedProp because I can format it to a value that is compatible with the rules I am making.

Again like I said, when only changing values it validates properly but when it comes to validateAll() it doesn't work anymore.

It's kind of not consistent.

@havgry
Copy link

havgry commented May 2, 2017

I replicated the issue here in a more simple version: http://jsfiddle.net/ye5hc7Lv/1/. Same result regardless of the value of name.

If you manually (or using the :value binding) set a value the field will be validated properly - at least in this basic case.

@logaretm
Copy link
Owner

logaretm commented Jun 8, 2017

Sorry for not being active in resolving the issue, The issue was caused by the validator not resolving the current value properly with computed values that are not bound to the elements, causing the el.value and the actual computed property value different in most cases.

It is currently resolved by treating the arg as a psudo model, by providing an arg it is the same as you provide a v-model binding to the validator point of view at least, the validator will check the model (arg) value if it was provided instead of the element value.

@maksnester
Copy link

Have this issue with computed with set() and get() methods. getter isn't called after updates. v-model:computedProp doesn't help.

@devhossamali
Copy link

i have the same issue when using set() and get() for computed property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement a "nice to have" feature
Projects
None yet
Development

No branches or pull requests

5 participants