Skip to content

Improve elm.value update (fix #4392) #4402

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

Closed
wants to merge 7 commits into from
Closed

Improve elm.value update (fix #4392) #4402

wants to merge 7 commits into from

Conversation

defcc
Copy link
Member

@defcc defcc commented Dec 7, 2016

fix #4392

We should update the elm.value when in these cases:

  1. the elm is not active and the value is not equal to model.value
  2. the elm needs to be casted to number or trimed, and the casted value is not equal to model.value

defcc added 2 commits December 7, 2016 08:37
1. the elem is not active and the value is not equal to model.value
2. the elem need to be casted to number or trimed, and the casted value is not equal to model.value
}
}

export function isToNumber (modifiers: ?ASTModifiers, type: ?string): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you can use a better name, as isToNumber isn't the most meaningful of them IMHO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, I'll try to find a better one

}

export function isToNumber (modifiers: ?ASTModifiers, type: ?string): boolean {
return modifiers && modifiers.number || (type === 'number')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The brackets are unnecessary, aren't they?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. && has higher priority, just to make it explicitly. I'll update it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For logical operator && ||, updated the coding style to keep consistent with other codes

return directive.modifiers
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this function is not problem, however, If modifier did not find, in end of function,
when you explicitly return, we can easily understand about this function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an explictly return undefined statement

@defcc defcc changed the title Improve elm.value update (fix #4392) [wip]Improve elm.value update (fix #4392) Dec 7, 2016
@defcc
Copy link
Member Author

defcc commented Dec 7, 2016

@yyx990803 CI dosen't run, will you please help to have a check on it ?

@defcc defcc changed the title [wip]Improve elm.value update (fix #4392) Improve elm.value update (fix #4392) Dec 7, 2016
const needNumber = (modifiers && modifiers.number) || vnode.elm.type === 'number'
const needTrim = modifiers && modifiers.trim
if (needNumber) {
return toNumber(value, val) !== toNumber(val)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first toNumber has an extra argument

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll correct it

return directive.modifiers
}
}
return undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't better to return an empty object so at the top you can do modifiers.number instead of modifiers && modifiers.number?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks

@yyx990803
Copy link
Member

I found an easier way: simply prevent updating when in focus, and force update on blur (see 8a7b02a)

Thanks for the PR still, used your test cases :)

@yyx990803 yyx990803 closed this Dec 8, 2016
@yyx990803
Copy link
Member

Hmm, looks like the isValueChanged check is indeed needed (e2e tests failing after my patch). Wondering if there's a way to simplify it...

yyx990803 added a commit that referenced this pull request Dec 8, 2016
@yyx990803
Copy link
Member

I ended up including your isValueChanged check to ensure correct behavior in e2e, sorry for closing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Input [v-model & type=number] is truncated when (unrelated) DOM update happens.
5 participants