phoenixwong / vue2-timepicker

A dropdown time picker (hour|minute|second) for Vue 2.x, with flexible time format support
https://phoenixwong.github.io/vue2-timepicker/
MIT License
432 stars 193 forks source link

Support value prop and data in the blur event #138

Closed kerbo closed 3 years ago

kerbo commented 3 years ago

A common usage pattern is to not use v-model but instead populate the field using :value. The value is then saved to store using the blur event.

My request is to:

Please add the value prop.

Please add the same data passed by the Change event to the Blur event.

phoenixwong commented 3 years ago

First of all, in Vue v2.x, the v-model is the short-hand of :value --

// Using `v-model`
<custom-component v-model="yourVar"></custom-component>

// Equals the following
<custom-component :value="yourVar" @input="yourVar = $event"></custom-component>

Documentation: https://vuejs.org/v2/guide/components.html#Using-v-model-on-Components

So there's no need to "add the value prop".


Please add the same data passed by the Change event to the Blur event

This one is workable. I'll make it an enhancement.

kerbo commented 3 years ago

Using v-model means I'm binding to a variable and that variable is being being updated by the input event. I do not want this. My intention is to use the blur event save the data elsewhere.

As I said, not using v-model is a common usage pattern and for every other component I use, the value prop is directly supported.

phoenixwong commented 3 years ago

As mentioned in my last comment, v-model is just a syntactic sugar of a combination of :value and @input. All custom components (E.g., Vue2 Timepicker) support v-model support :value naturally.

That's what I meant by saying there's no need to "add the value prop".

<!-- It works in any existing Vue2 Timepicker version-->
<vue-timepicker :value="yourVar"></vue-timepicker>

Check JSFiddle Demo here


UPDATE: The Lazy Event Mode may be what you are looking for -- it makes sure both input and change event fires when

<vue-timepicker lazy></vue-timepicker>

Documentation here