From 98a56b782d1ced056c77019e88b4bcea4a270f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 1 Oct 2021 11:49:26 +0200 Subject: Reintroduce dateonly for date-time-input:s. --- static/globals.js | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'static/globals.js') 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 = '' } + 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); +} -- cgit v1.2.3