aboutsummaryrefslogtreecommitdiff
path: root/static/globals.js
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2021-10-01 11:49:26 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2021-10-01 11:49:26 +0200
commit98a56b782d1ced056c77019e88b4bcea4a270f83 (patch)
treeccfb714dc111c7437f2cdf52b956d95d954ad4df /static/globals.js
parentRemove old date_time system. (diff)
downloadcalp-98a56b782d1ced056c77019e88b4bcea4a270f83.tar.gz
calp-98a56b782d1ced056c77019e88b4bcea4a270f83.tar.xz
Reintroduce dateonly for date-time-input:s.
Diffstat (limited to '')
-rw-r--r--static/globals.js40
1 files changed, 38 insertions, 2 deletions
diff --git a/static/globals.js b/static/globals.js
index 4ee3c62a..fd576e26 100644
--- a/static/globals.js
+++ b/static/globals.js
@@ -318,10 +318,40 @@ class DateTimeInput extends HTMLElement {
this.innerHTML = '<input type="date" /><input type="time" />'
}
+ static get observedAttributes () {
+ return [ 'dateonly' ]
+ }
+
+ attributeChangedCallback (name, from, to) {
+ console.log(this, name, boolean(from), boolean(to));
+ switch (name) {
+ case 'dateonly':
+ this.querySelector('[type="time"]').disabled = boolean(to)
+ break;
+ }
+ }
+
+ get dateonly () {
+ return boolean(this.getAttribute('dateonly'));
+ }
+
+ set dateonly (bool) {
+ this.setAttribute ('dateonly', bool);
+ }
+
get value () {
+
+ let dt;
let date = this.querySelector("[type='date']").value;
- let time = this.querySelector("[type='time']").value;
- return parseDate(date + 'T' + time)
+ if (boolean(this.getAttribute('dateonly'))) {
+ dt = parseDate(date);
+ dt.type = 'date';
+ } else {
+ let time = this.querySelector("[type='time']").value;
+ dt = parseDate(date + 'T' + time)
+ dt.type = 'date-time';
+ }
+ return dt;
}
set value (new_value) {
@@ -345,3 +375,9 @@ class DateTimeInput extends HTMLElement {
}
customElements.define('date-time-input', DateTimeInput)
+
+function wholeday_checkbox (box) {
+ box.closest('.timeinput')
+ .getElementsByTagName('date-time-input')
+ .forEach(el => el.dateonly = box.checked);
+}