Skip to content

Commit

Permalink
Merge pull request #76 from vaadin/demo-ignore-ie
Browse files Browse the repository at this point in the history
Ignore ES6 demo in IE11, move custom formatter demo [skip ci]
  • Loading branch information
tomivirkki authored Sep 27, 2018
2 parents ac426a5 + 135f812 commit bfb51ab
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"webcomponentsjs": "^1.0.0",
"web-component-tester": "^6.1.5",
"test-fixture": "^3.0.0",
"vaadin-demo-helpers": "vaadin/vaadin-demo-helpers#^2.0.2",
"vaadin-demo-helpers": "vaadin/vaadin-demo-helpers#^2.1.0",
"iron-form": "^2.3.0"
}
}
41 changes: 38 additions & 3 deletions demo/time-picker-advanced-demos.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,47 @@
:host {
display: block;
}

</style>

<h3>Custom Parser And Formatter</h3>
<vaadin-demo-snippet id="time-picker-advanced-demos-format-parse-example">
<template preserve-content>
<vaadin-time-picker label="Arrival hour"></vaadin-time-picker>
<script>
window.addDemoReadyListener('#time-picker-advanced-demos-format-parse-example', function(document) {
const timePicker = document.querySelector('vaadin-time-picker');

timePicker.i18n = {
formatTime: function(timeObject) {
if (timeObject) {
const pad = function(n) {
n = parseInt(n || 0);
return n < 10 ? '0' + n : n;
};
const period = timeObject.hours > 12 ? 'PM' : 'AM';
const hours = timeObject.hours % 12 || 12;
return pad(hours) + ':' + pad(timeObject.minutes) + ' ' + period;
}
},
parseTime: function(timeString) {
if (timeString) {
const parts = /^(\d{1,2})(?::(\d{1,2}))?(?:\s(\w{2}))?$/.exec(timeString);
return parts && {
hours: parseInt(parts[1]) + (parts[3] == 'PM' ? 12 : 0),
minutes: parts[2]
};
}
}
};
});
</script>
</template>
</vaadin-demo-snippet>

<h3>Custom Validator</h3>
<p>Extend <code>Vaadin.TimePickerElement</code> to create your own custom element,
then override the <code>checkValidity()</code> method to validate the input.
<vaadin-demo-snippet id="time-picker-advanced-demos-custom-validator">
then override the <code>checkValidity()</code> method to validate the input.</p>
<vaadin-demo-snippet id="time-picker-advanced-demos-custom-validator" ignore-ie>
<template preserve-content>
<vaadin-time-picker-working-hours label="Delivery hour"
error-message="Select a vaild working hour (9:00 to 17:00)"></vaadin-time-picker-working-hours>
Expand Down
35 changes: 0 additions & 35 deletions demo/time-picker-basic-demos.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,6 @@ <h3>Value Resolution</h3>
</template>
</vaadin-demo-snippet>

<h3>Custom Parser And Formatter</h3>
<vaadin-demo-snippet id="time-picker-basic-demos-format-parse-example">
<template preserve-content>
<vaadin-time-picker label="Arrival hour"></vaadin-time-picker>
<script>
window.addDemoReadyListener('#time-picker-basic-demos-format-parse-example', function(document) {
const timePicker = document.querySelector('vaadin-time-picker');

timePicker.i18n = {
formatTime: function(timeObject) {
if (timeObject) {
const pad = function(n) {
n = parseInt(n || 0);
return n < 10 ? '0' + n : n;
};
const period = timeObject.hours > 12 ? 'PM' : 'AM';
const hours = timeObject.hours % 12 || 12;
return pad(hours) + ':' + pad(timeObject.minutes) + ' ' + period;
}
},
parseTime: function(timeString) {
if (timeString) {
const parts = /^(\d{1,2})(?::(\d{1,2}))?(?:\s(\w{2}))?$/.exec(timeString);
return parts && {
hours: parseInt(parts[1]) + (parts[3] == 'PM' ? 12 : 0),
minutes: parts[2]
};
}
}
};
});
</script>
</template>
</vaadin-demo-snippet>

</template>
<script>
class TimePickerBasicDemos extends DemoReadyEventEmitter(ElementDemo(Polymer.Element)) {
Expand Down

0 comments on commit bfb51ab

Please sign in to comment.