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

Validation not working when using model less validation with a default value. #2353

Closed
Ricky-rick opened this issue Sep 20, 2019 · 0 comments · Fixed by #2355
Closed

Validation not working when using model less validation with a default value. #2353

Ricky-rick opened this issue Sep 20, 2019 · 0 comments · Fixed by #2355

Comments

@Ricky-rick
Copy link
Contributor

Ricky-rick commented Sep 20, 2019

Versions

  • vee-validate: 3.0.6
  • vue: 2.6.10

The validation not working correct when using model less validation with a default value.
This is especially a problem when using render functions that doesn't support v-model.

To reproduce
Steps to reproduce the behavior:

  1. Go to see https://codesandbox.io/s/veevalidate-30-async-rule-example-i6x7x
  2. Click on check
  3. See the incorrect validation error

Expected behavior
No validation error because we have an initial value

Demo link
https://codesandbox.io/s/veevalidate-30-async-rule-example-i6x7x

Additional context
Some investigation brought me to the findModel method .
This function returns undefined and that causes that the extractVNodes function returns an empty array.
That will cause that the addListeners will not be called and the onRenderUpdate method can not set the (initial) value

Possible fix on the findModel method:

export function findModel(vnode: VNode): VNodeDirective | undefined {
  if (!vnode.data) {
    return undefined;
  }

  // Component Model
  // THIS IS NOT TYPED IN OFFICIAL VUE TYPINGS
  // eslint-disable-next-line
  const nonStandardVNodeData = vnode.data as any;
  if ('model' in nonStandardVNodeData) {
    return nonStandardVNodeData.model;
  }

++    if (vnode.data.props && 'value' in vnode.data.props) {
++      return {value:  vnode.data.props.value}
++    }
++
  if (!vnode.data.directives) {
    return undefined;
  }

  return find(vnode.data.directives, d => d.name === 'model');
}
@Ricky-rick Ricky-rick changed the title Validation not working when using manual validation with a default value. Validation not working when using model less validation with a default value. Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant