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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 2378 #2381

Merged
merged 2 commits into from Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/common.ts
@@ -1,4 +1,4 @@
import { VNodeDirective, VNode } from 'vue';
import { VNode } from 'vue';
import { isCallable, debounce, identity } from '../utils';
import { modes, InteractionModeFactory } from '../modes';
import { ValidationResult, ValidationFlags, KnownKeys, ProviderInstance } from '../types';
Expand Down Expand Up @@ -153,7 +153,7 @@ export function addListeners(vm: ProviderInstance, node: VNode) {
const value = findValue(node);
// cache the input eventName.
vm._inputEventName = vm._inputEventName || getInputEventName(node, findModel(node));
onRenderUpdate(vm, value);
onRenderUpdate(vm, value && value.value);

const { onInput, onBlur, onValidate } = createCommonHandlers(vm);
addVNodeListener(node, vm._inputEventName, onInput);
Expand Down
2 changes: 1 addition & 1 deletion src/components/withValidation.ts
Expand Up @@ -37,7 +37,7 @@ export function withValidation(component: ComponentLike, mapProps: ValidationCon
const model = findModel(this.$vnode);
this._inputEventName = this._inputEventName || getInputEventName(this.$vnode, model);
const value = findValue(this.$vnode);
onRenderUpdate(this, value);
onRenderUpdate(this, value && value.value);

const { onInput, onBlur, onValidate } = createCommonHandlers(this);

Expand Down
12 changes: 7 additions & 5 deletions src/utils/vnode.ts
Expand Up @@ -44,19 +44,21 @@ export function findModel(vnode: VNode): VNodeDirective | undefined {
return find(vnode.data.directives, d => d.name === 'model');
}

export function findValue(vnode: VNode): any | undefined {
export function findValue(vnode: VNode): { value: any } | undefined {
const model = findModel(vnode);
if (model) {
return model.value;
return { value: model.value };
}

if (vnode.componentOptions && vnode.componentOptions.propsData && 'value' in vnode.componentOptions.propsData) {
const config = findModelConfig(vnode);
const prop = (config && config.prop) || 'value';
if (vnode.componentOptions && vnode.componentOptions.propsData && prop in vnode.componentOptions.propsData) {
const propsDataWithValue = vnode.componentOptions.propsData as any;
return propsDataWithValue.value;
return { value: propsDataWithValue[prop] };
}

if (vnode.data && vnode.data.domProps && 'value' in vnode.data.domProps) {
return vnode.data.domProps.value;
return { value: vnode.data.domProps.value };
}

return undefined;
Expand Down