Skip to content

Commit f39df7b

Browse files
Fixes #5
1 parent a60bf16 commit f39df7b

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

demo/index.html

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,45 @@
3838

3939
<p>An example of <code>&lt;paper-input-date-picker&gt;</code> with validaton messages:</p>
4040
<paper-input-date-picker id="dynInputDate" label="Pick a date..."></paper-input-date-picker>
41+
42+
<paper-button on-tap="onClickDynSetMinDate" auto-validate>Set Min Date</paper-button>
43+
44+
<paper-button on-tap="onClickDynSetMaxDate" auto-validate>Set Max Date</paper-button>
4145

42-
<paper-button label="Teste" on-tap="onClickDynValidation" auto-validate>Validate</paper-button>
46+
<paper-button on-tap="onClickDynValidation" auto-validate>Validate</paper-button>
4347

4448
<script>
4549

4650
window.addEventListener('WebComponentsReady', function() {
4751

4852
var app = document.querySelector('#app');
53+
54+
app.onClickDynSetMinDate = function () {
55+
var numberDaysBeforeToday = 10;
56+
var daysToTimestampCalcFactor = 24 * 60 * 60 * 1000;
57+
58+
// Subtract some days from today.
59+
var timestampDaysToSubtract = (numberDaysBeforeToday * daysToTimestampCalcFactor);
60+
var minDate = new Date((new Date()).valueOf() - timestampDaysToSubtract)
61+
62+
this.$.dynInputDate.minDate = minDate;
63+
};
4964

65+
app.onClickDynSetMaxDate = function () {
66+
var numberDaysAfterToday = 10;
67+
var daysToTimestampCalcFactor = 24 * 60 * 60 * 1000;
68+
69+
// Add some days from today.
70+
var timestampDaysToAdd = (numberDaysAfterToday * daysToTimestampCalcFactor);
71+
var maxDate = new Date((new Date()).valueOf() + timestampDaysToAdd)
72+
73+
this.$.dynInputDate.maxDate = maxDate;
74+
};
75+
5076
app.onClickDynValidation = function () {
5177

5278
this.$.dynInputDate.errorMessage = 'Errooooooo';
5379
this.$.dynInputDate.setAttribute('invalid', 'true');
54-
55-
console.log('ssdsas', this.$.dynInputDate.value);
5680
};
5781
});
5882
</script>

paper-input-date-picker.html

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
</paper-input>
111111
</paper-button>
112112
<paper-dialog id="dialog" class="paper-date-picker-dialog" modal="[[modal]]" on-iron-overlay-closed="_dismissDialog">
113-
<paper-date-picker id="picker" locale="{{locale}}"></paper-date-picker>
113+
<paper-date-picker id="picker" locale="[[locale]]" min-date="[[_computeMinDate(minDate)]]" max-date="[[_computeMaxDate(maxDate)]]"></paper-date-picker>
114114
<div class="buttons">
115115
<paper-button dialog-dismiss on-tap="_onTapClearValue" class="btn-clear">Clear</paper-button>
116116
<paper-button dialog-dismiss>Cancel</paper-button>
@@ -194,9 +194,20 @@
194194
* For localization formatting.
195195
*/
196196
locale: {
197-
type: String
197+
type: String,
198+
notify: true
198199
},
199200

201+
minDate: {
202+
type: Date,
203+
notify: true
204+
},
205+
206+
maxDate: {
207+
type: Date,
208+
notify: true
209+
},
210+
200211
keyEventTarget: {
201212
type: Object,
202213
value: function() {
@@ -218,6 +229,22 @@
218229
return this.$.input;
219230
},
220231

232+
_computeMinDate: function (minDate) {
233+
if (minDate) {
234+
return minDate;
235+
}
236+
237+
return null;
238+
},
239+
240+
_computeMaxDate: function (maxDate) {
241+
if (maxDate) {
242+
return maxDate;
243+
}
244+
245+
return null;
246+
},
247+
221248
listeners: {
222249
'focus': '_onFocus'
223250
},

0 commit comments

Comments
 (0)