Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Commit

Permalink
Respect min date on default selection
Browse files Browse the repository at this point in the history
  • Loading branch information
npostulart committed Oct 9, 2018
1 parent 56bac54 commit f8e40ea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
22 changes: 22 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ <h2>Macro tokens</h2>
</div>
</div>

<h2>Default min date</h2>

<div class="example">
<div class="example-inputs">
<datetime type="datetime" v-model="datetimeMin" placeholder="Select date" :min-datetime="minDatetimePlus" :max-datetime="maxDatetimePlus"></datetime>

<div class="values">
<p>
<strong>Value:</strong> {{ datetimeMin }}
</p>
</div>
</div>
<div class="example-code">
<pre><code>&#x3C;datetime
type=&#x22;datetime&#x22;
v-model=&#x22;datetimeMin&#x22;
:min-datetime=&#x22;minDatetimePlus&#x22;
:max-datetime=&#x22;maxDatetimePlus&#x22;
&#x3E;&#x3C;/datetime&#x3E;</code></pre>
</div>
</div>

<h2>Complete demo</h2>

<div class="example">
Expand Down
5 changes: 4 additions & 1 deletion demo/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ new Vue({
datetime: '2018-05-12T17:19:06.151Z',
datetime12: '2018-05-12T17:19:06.151Z',
datetime13: '2018-05-12T17:19:06.151Z',
datetimeMin: '',
datetimeEmpty: '',
minDatetime: LuxonDateTime.local().minus({ days: 3 }).toISO(),
maxDatetime: LuxonDateTime.local().plus({ days: 3 }).toISO(),
datetimeTheming: LuxonDateTime.local().toISO()
datetimeTheming: LuxonDateTime.local().toISO(),
minDatetimePlus: LuxonDateTime.local().plus({ days: 3 }).toISO(),
maxDatetimePlus: LuxonDateTime.local().plus({ days: 7 }).toISO()
}
}
})
Expand Down
10 changes: 9 additions & 1 deletion src/Datetime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,15 @@ export default {
this.close()
},
newPopupDatetime () {
const datetime = DateTime.utc().setZone(this.zone).set({ seconds: 0, milliseconds: 0 })
let datetime = DateTime.utc().setZone(this.zone).set({ seconds: 0, milliseconds: 0 })
if (this.popupMinDatetime && datetime < this.popupMinDatetime) {
datetime = this.popupMinDatetime.set({ seconds: 0, milliseconds: 0 })
}
if (this.popupMaxDatetime && datetime > this.popupMaxDatetime) {
datetime = this.popupMaxDatetime.set({ seconds: 0, milliseconds: 0 })
}
if (this.minuteStep === 1) {
return datetime
Expand Down

0 comments on commit f8e40ea

Please sign in to comment.