Skip to content

Commit b8d8a51

Browse files
committed
feat(QDate): docs + new method setViewTo(year, month)
1 parent d860ce6 commit b8d8a51

File tree

3 files changed

+43
-19
lines changed

3 files changed

+43
-19
lines changed

docs/src/pages/vue-components/date.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ For handling date and/or time, also check out [Quasar Date Utils](/quasar-utils/
1919
## Usage
2020

2121
::: warning
22-
Notice that the model is a String only.
22+
Notice that the actual date(s) of the model are all in String format.
2323
:::
2424

2525
### Basic
@@ -42,12 +42,16 @@ Clicking on an already selected day will deselect it.
4242

4343
### Range selection <q-badge align="top" label="v1.13+" />
4444

45-
Notice in the examples below that the model is an Array of Arrays.
45+
Notice in the examples below that the model is an Object (single selection) or an Array of Objects (multiple selection).
4646

47-
Clicking on an already selected day will deselect it.
47+
::: tip TIPS
48+
* Clicking on an already selected day will deselect it.
49+
* The user's current editing range can also be set programmatic through the `setEditingRange` method (check the API card).
50+
* There are two useful events in regards to the current editing range: `range-start` and `range-end` (check the API card).
51+
:::
4852

4953
::: warning
50-
The `range` property is partially compatible with the `options` prop: selected ranges might also include "unselectable" days.
54+
The `range` property is only partially compatible with the `options` prop: selected ranges might also include "unselectable" days.
5155
:::
5256

5357
<doc-example title="Single Range" file="QDate/SelectionRange" overflow />

ui/src/components/date/QDate.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export default Vue.extend({
147147
return this.normalizedModel
148148
.filter(date => Object(date) === date && date.from !== void 0 && date.to !== void 0)
149149
.map(range => ({ from: fn(range.from), to: fn(range.to) }))
150-
.filter(range => range.from.dateHash !== null && range.to.dateHash !== null)
150+
.filter(range => range.from.dateHash !== null && range.to.dateHash !== null && range.from.dateHash < range.to.dateHash)
151151
},
152152

153153
getNativeDateFn () {
@@ -686,8 +686,7 @@ export default Vue.extend({
686686
methods: {
687687
setToday () {
688688
this.__toggleDate(this.today, this.__getMonthHash(this.today))
689-
this.view = 'Calendar'
690-
this.__updateViewModel(this.today.year, this.today.month)
689+
this.setViewTo(this.today.year, this.today.month)
691690
},
692691

693692
setView (view) {
@@ -704,6 +703,11 @@ export default Vue.extend({
704703
}
705704
},
706705

706+
setViewTo (year, month) {
707+
this.view = 'Calendar'
708+
this.__updateViewModel(year, month)
709+
},
710+
707711
setEditingRange (from, to) {
708712
if (this.range === false || !from) {
709713
this.editRange = void 0
@@ -722,8 +726,7 @@ export default Vue.extend({
722726
finalHash: this.__getDayHash(final)
723727
}
724728

725-
this.view = 'Calendar'
726-
this.__updateViewModel(init.year, init.month)
729+
this.setViewTo(init.year, init.month)
727730
},
728731

729732
__getMask () {
@@ -1216,13 +1219,13 @@ export default Vue.extend({
12161219
? { from: this.editRange.init, to: day }
12171220
: { from: day, to: this.editRange.init }
12181221

1222+
this.editRange = void 0
1223+
this.__addToModel(initHash === finalHash ? day : payload)
1224+
12191225
this.$emit('range-end', {
12201226
from: this.__getPublicData(payload.from),
12211227
to: this.__getPublicData(payload.to)
12221228
})
1223-
1224-
this.editRange = void 0
1225-
this.__addToModel(initHash === finalHash ? day : payload)
12261229
}
12271230
},
12281231

ui/src/components/date/QDate.json

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@
265265
"params": {
266266
"from": {
267267
"type": "Object",
268-
"desc": "Definition of the current view (year, month)",
268+
"desc": "Definition of date from where the range begins",
269269
"definition": {
270270
"year": {
271271
"type": "Number",
@@ -297,7 +297,7 @@
297297
"definition": {
298298
"from": {
299299
"type": "Object",
300-
"desc": "Definition of the current view (year, month)",
300+
"desc": "Definition of date from where the range begins",
301301
"definition": {
302302
"year": {
303303
"type": "Number",
@@ -318,7 +318,7 @@
318318
},
319319
"to": {
320320
"type": "Object",
321-
"desc": "Definition of the current view (year, month)",
321+
"desc": "Definition of date to where the range ends",
322322
"definition": {
323323
"year": {
324324
"type": "Number",
@@ -352,15 +352,32 @@
352352

353353
"setView": {
354354
"desc": "Change current view",
355-
"addedIn": "v1.1.7",
356355
"params": {
357356
"view": {
358357
"type": "String",
359358
"desc": "QDate view name",
360359
"required": true,
361360
"values": [ "Calendar", "Months", "Years" ]
362361
}
363-
}
362+
},
363+
"addedIn": "v1.1.7"
364+
},
365+
366+
"setViewTo": {
367+
"desc": "Change current year and month of the Calendar view; It gets corrected if using navigation-min/max-year-month and sets the current view to Calendar",
368+
"params": {
369+
"year": {
370+
"type": "Number",
371+
"desc": "The year",
372+
"__exemption": [ "examples" ]
373+
},
374+
"month": {
375+
"type": "Number",
376+
"desc": "The month",
377+
"__exemption": [ "examples" ]
378+
}
379+
},
380+
"addedIn": "v1.13.0"
364381
},
365382

366383
"offsetCalendar": {
@@ -385,7 +402,7 @@
385402
"params": {
386403
"from": {
387404
"type": "Object",
388-
"desc": "Definition of the current view (year, month)",
405+
"desc": "Definition of date from where the range begins",
389406
"definition": {
390407
"year": {
391408
"type": "Number",
@@ -406,7 +423,7 @@
406423
},
407424
"to": {
408425
"type": "Object",
409-
"desc": "Definition of the current view (year, month)",
426+
"desc": "Definition of date to where the range ends",
410427
"definition": {
411428
"year": {
412429
"type": "Number",

0 commit comments

Comments
 (0)