Skip to content

Commit

Permalink
fix: 2378 (#2381)
Browse files Browse the repository at this point in the history
* feat: handle different configuration for model value detection

* fix: improve early escape detection after finding model closes #2378
  • Loading branch information
logaretm committed Sep 26, 2019
1 parent 1e567cc commit 53add5e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
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

0 comments on commit 53add5e

Please sign in to comment.