Skip to content

Commit e87a6af

Browse files
committed
Merge branch 'release/v2.10.0'
2 parents e87e413 + 13ae99e commit e87a6af

10 files changed

+228
-133
lines changed

README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,22 @@ This project is licensed under the MIT License
129129

130130
## Change log
131131

132+
### 2.10.0 (2021-11-03)
133+
* Feat: Added support for display format when using [`custom-input`](https://talkhabi.github.io/vue-persian-datetime-picker/guide/custom-input.html)
134+
132135
### 2.9.1 (2021-10-31)
133136
* Fixed: [Using jumpMinute and roundMinute together](https://github.com/talkhabi/vue-persian-datetime-picker/issues/182)
134137

135138
### 2.9.0 (2021-09-27)
136-
* Feat: [Added simple-mode](https://talkhabi.github.io/vue-persian-datetime-picker/#/simple-mode)
139+
* Feat: [Added simple-mode](https://talkhabi.github.io/vue-persian-datetime-picker/guide/simple-mode.html)
137140
* Feat: [Added `input-attrs`](https://github.com/talkhabi/vue-persian-datetime-picker/issues/170)
138141
* Feat: [Added `@next-month` and `@prev-month` events](https://github.com/talkhabi/vue-persian-datetime-picker/issues/176)
139142
* Feat: Added `@year-change` and `@month-change` events
140143
* Fixed: [Mouse wheel in Firefox](https://github.com/talkhabi/vue-persian-datetime-picker/issues/174)
141144
* Fixed: Prevent selected dates from being reset
142145

143146
### 2.8.0 (2021-08-01)
144-
* Feat: [Added ability to control route in show/close action](https://talkhabi.github.io/vue-persian-datetime-picker/#/use-router)
147+
* Feat: [Added ability to control route in show/close action](https://talkhabi.github.io/vue-persian-datetime-picker/guide/use-router.html)
145148
* Fixed Date change animation and transition
146149

147150
### 2.7.0 (2021-07-23)
@@ -154,12 +157,12 @@ This project is licensed under the MIT License
154157
* Fixed [year-month](https://github.com/talkhabi/vue-persian-datetime-picker/issues/150)
155158

156159
### 2.6.0 (2021-02-05)
157-
* Added [multiple selection](https://talkhabi.github.io/vue-persian-datetime-picker/#/multiple) (for type `date` only)
158-
* Added [popover mode](https://talkhabi.github.io/vue-persian-datetime-picker/#/popover)
160+
* Added [multiple selection](https://talkhabi.github.io/vue-persian-datetime-picker/guide/multiple.html) (for type `date` only)
161+
* Added [popover mode](https://talkhabi.github.io/vue-persian-datetime-picker/guide/popover.html)
159162
* Close picker with `escape` key, fixes [#141](https://github.com/talkhabi/vue-persian-datetime-picker/issues/141)
160163

161164
### 2.5.0 (2021-01-30)
162-
* Added [range option](https://talkhabi.github.io/vue-persian-datetime-picker/#/range) (for type `date` only)
165+
* Added [range option](https://talkhabi.github.io/vue-persian-datetime-picker/guide/range.html) (for type `date` only)
163166
* Fixed [#136](https://github.com/talkhabi/vue-persian-datetime-picker/issues/136)
164167

165168
### 2.4.1 (2020-11-13)
@@ -176,8 +179,8 @@ This project is licensed under the MIT License
176179
* Added [`convert-numbers`](https://github.com/talkhabi/vue-persian-datetime-picker/pull/117) prop that converts numbers to persian in fa locale: `<date-picker convert-numbers />`
177180

178181
### 2.2.0 (2020-08-02)
179-
* [Custom localization](https://talkhabi.github.io/vue-persian-datetime-picker/#/locale) is now supported
180-
* Added some [slots](https://talkhabi.github.io/vue-persian-datetime-picker/#/slots)
182+
* [Custom localization](https://talkhabi.github.io/vue-persian-datetime-picker/guide/localization.html) is now supported
183+
* Added some [slots](https://talkhabi.github.io/vue-persian-datetime-picker/guide/slots.html)
181184

182185
### 2.1.6 (2020-07-13)
183186
* Fixed `locale-config` prop [#116](https://github.com/talkhabi/vue-persian-datetime-picker/issues/116)

dist/vue-persian-datetime-picker.common.js

+53-33
Large diffs are not rendered by default.

dist/vue-persian-datetime-picker.umd.js

+53-33
Large diffs are not rendered by default.

dist/vue-persian-datetime-picker.umd.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/config/README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ Editable input or just readonly
9494

9595

9696
## element
97-
98-
The specified input element ID
97+
Deprecated, Use [customInput](/config/#custominput)
9998

10099
Sometimes you don't want to use picker default input,
101100
so you can use our own input element with `id` attribute
@@ -104,6 +103,16 @@ so you can use our own input element with `id` attribute
104103
- Example: `the-id-of-custom-input`
105104

106105

106+
## customInput
107+
New version of `element`
108+
use this instead of `element`, this custom input does not need v-model, and it will be automatically updated
109+
also supports `display-format`
110+
- Type: String (DOMString containing a selector list)
111+
- Default: `undefined`
112+
- Example: `.my-custom-input`
113+
- Version: `>= 2.10.0`
114+
115+
107116
## name
108117

109118
The form input name (when you are not using `element`)

docs/guide/custom-input.md

+54-38
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
# Custom input
22

3+
- #### Using `custom-input` prop
34
```vue
45
<input
5-
id="my-custom-input"
6-
v-model="date"
76
type="text"
8-
class="form-control"
7+
class="custom-input"
98
placeholder="select date"
109
/>
10+
<span>date = {{ date }}</span>
1111
1212
<date-picker
1313
v-model="date"
14-
format="jYYYY/jMM/jDD"
15-
element="my-custom-input"
14+
format="YYYY-MM-DD"
15+
display-format="jYYYY-jMM-jDD"
16+
custom-input=".custom-input"
1617
/>
1718
```
1819
```js
@@ -30,6 +31,7 @@ export default {
3031
data() {
3132
return {
3233
date: '',
34+
date1: '',
3335
date2: '',
3436
show: false
3537
}
@@ -38,84 +40,96 @@ export default {
3840
</script>
3941

4042
<input
41-
id="my-custom-input"
42-
v-model="date"
4343
type="text"
44-
class="form-control"
44+
class="custom-input form-control"
4545
placeholder="select date"
4646
/>
4747

48+
<code>date = {{ date }}</code>
49+
4850
<ClientOnly>
4951
<date-picker
5052
v-model="date"
51-
format="jYYYY/jMM/jDD"
52-
element="my-custom-input"
53+
format="YYYY-MM-DD"
54+
display-format="jYYYY-jMM-jDD"
55+
custom-input=".custom-input"
5356
/>
5457
</ClientOnly>
5558

56-
::: danger
57-
Custom input does not support `display-format`.
58-
59-
You have to create a specific component for this purpose or use a computed property.
6059

61-
See the following example:
62-
:::
60+
- #### Method B: Using `element` prop (deprecated)
6361

62+
:::details show example
6463
```vue
6564
<input
6665
id="my-custom-input"
67-
v-model="dateFormatted"
66+
v-model="date"
6867
type="text"
6968
class="form-control"
7069
placeholder="select date"
7170
/>
7271
7372
<date-picker
7473
v-model="date"
75-
format="YYYY-MM-DD"
74+
format="jYYYY/jMM/jDD"
7675
element="my-custom-input"
7776
/>
7877
```
7978
```js
80-
import moment from 'moment-jalaali'
8179
export default {
8280
data() {
8381
return {
8482
date: ''
8583
}
86-
},
87-
computed: {
88-
dateFormatted() {
89-
return moment(this.date, 'YYYY-MM-DD').format('jYYYY/jMM/jDD')
90-
}
9184
}
9285
}
9386
```
9487

88+
<input
89+
id="my-custom-input"
90+
v-model="date1"
91+
type="text"
92+
class="form-control"
93+
placeholder="select date"
94+
/>
95+
96+
<ClientOnly>
97+
<date-picker
98+
v-model="date1"
99+
format="jYYYY/jMM/jDD"
100+
element="my-custom-input"
101+
/>
102+
</ClientOnly>
103+
104+
:::
105+
106+
107+
::: danger
108+
`element` does not support `display-format`.
109+
110+
please use `custom-input`.
111+
:::
112+
113+
95114
### Custom editable input
96115
```vue
97-
<button
98-
type="button"
99-
class="btn btn-primary"
100-
@click="show=true"
101-
>
116+
<button type="button" class="btn btn-primary" @click="show = true">
102117
Show Datepicker
103118
</button>
104119
105120
<input
106121
id="my-custom-editable-input"
107-
v-model="date"
108122
type="text"
109-
class="form-control is-editable"
110123
placeholder="YYYY/MM/DD"
111124
/>
112125
113126
<date-picker
114127
v-model="date"
115-
format="jYYYY/jMM/jDD"
116-
element="my-custom-editable-input"
117-
:editable="true"
118128
:show="show"
129+
:editable="true"
130+
format="YYYY-MM-DD"
131+
display-format="jYYYY/jMM/jDD"
132+
custom-input="#my-custom-editable-input"
119133
@close="show=false"
120134
/>
121135
```
@@ -139,17 +153,19 @@ Show Datepicker
139153
type="text"
140154
class="form-control is-editable"
141155
placeholder="YYYY/MM/DD"
142-
v-model="date2"
143156
id="my-custom-editable-input"
144157
/>
145158

159+
<code>date = {{ date2 }}</code>
160+
146161
<ClientOnly>
147162
<date-picker
148163
v-model="date2"
149-
format="jYYYY/jMM/jDD"
150-
element="my-custom-editable-input"
151-
:editable="true"
152164
:show="show"
165+
:editable="true"
166+
format="YYYY-MM-DD"
167+
display-format="jYYYY/jMM/jDD"
168+
custom-input="#my-custom-editable-input"
153169
@close="show=false"
154170
/>
155171
</ClientOnly>

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-persian-datetime-picker",
33
"description": "A vue plugin to select jalali date and time",
4-
"version": "2.9.1",
4+
"version": "2.10.0",
55
"private": false,
66
"author": "Mohammad Talkhabi",
77
"license": "MIT",

src/VuePersianDatetimePicker.vue

+31-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:class="{ 'vpd-is-popover': isPopover }"
99
>
1010
<span
11-
v-if="!element"
11+
v-if="!customInputElement"
1212
ref="inputGroup"
1313
:class="['vpd-input-group', { 'vpd-disabled': disabled }]"
1414
>
@@ -457,6 +457,7 @@ import SimpleMode from './components/simple/SimpleMode'
457457
import CoreModule from './modules/core'
458458
import { popupRouteChanger } from './modules/mixins'
459459
import { cloneDates, isSameDay } from './modules/utils'
460+
import { addLiveEvent } from './modules/utils'
460461
461462
export default {
462463
components: {
@@ -575,6 +576,7 @@ export default {
575576
editable: { type: Boolean, default: false },
576577
577578
/**
579+
* @deprecated
578580
* The specified input element ID
579581
* @type String
580582
* @default Undefined
@@ -584,6 +586,17 @@ export default {
584586
*/
585587
element: { type: String, default: undefined },
586588
589+
/**
590+
* New version of `element`
591+
* @type String (DOMString containing a selector list)
592+
* @desc use this instead of `element`,
593+
* this custom input does not need v-model, and it will be automatically updated
594+
* also supports `display-format`
595+
* @example .my-custom-input | #my-custom-input | div.foo > input
596+
* @version 2.10.0
597+
*/
598+
customInput: { type: String, default: undefined },
599+
587600
/**
588601
* The form input name when not using {element}
589602
* @type String
@@ -1176,6 +1189,10 @@ export default {
11761189
},
11771190
isCompactTime() {
11781191
return this.compactTime || (this.type === 'datetime' && this.simple)
1192+
},
1193+
customInputElement() {
1194+
if (this.element) return `#${this.element}`
1195+
return this.customInput
11791196
}
11801197
},
11811198
watch: {
@@ -1253,6 +1270,14 @@ export default {
12531270
'localeData.name'() {
12541271
this.$emit('localeChange', this.localeData)
12551272
this.setMinMax()
1273+
},
1274+
displayValue: {
1275+
immediate: true,
1276+
handler: function(displayValue) {
1277+
if (!this.customInput) return
1278+
const customInput = document.querySelector(this.customInput)
1279+
if (customInput) customInput.value = displayValue
1280+
}
12561281
}
12571282
},
12581283
created() {
@@ -1262,21 +1287,10 @@ export default {
12621287
},
12631288
mounted() {
12641289
this.$nextTick(() => {
1265-
let addEvent = (el, type, handler) => {
1266-
if (el.attachEvent) el.attachEvent('on' + type, handler)
1267-
else el.addEventListener(type, handler)
1268-
}
1269-
let live = (selector, event, callback, context) => {
1270-
addEvent(context || document, event, function(e) {
1271-
let found,
1272-
el = e.target || e.srcElement
1273-
while (el && !(found = el.id === selector)) el = el.parentElement
1274-
if (found) callback.call(el, e)
1275-
})
1276-
}
1277-
if (this.element && !this.editable) {
1278-
live(this.element, 'click', this.focus)
1279-
}
1290+
if (this.customInputElement && !this.editable)
1291+
addLiveEvent(this.customInputElement, 'click', this.focus)
1292+
if (this.customInput && this.editable)
1293+
addLiveEvent(this.customInput, 'blur', this.setOutput)
12801294
})
12811295
document.body.addEventListener('keydown', e => {
12821296
e = e || event
@@ -1435,7 +1449,7 @@ export default {
14351449
}
14361450
},
14371451
updateDates(payload) {
1438-
if (this.isDataArray && !payload) payload = []
1452+
if (!payload) payload = this.isDataArray ? [] : ''
14391453
14401454
// fix: don't update dates if they are already up to date
14411455
if (this.date.clone && payload.toString() === this.outputValue.toString())

0 commit comments

Comments
 (0)