Skip to content

Commit

Permalink
use proper calendar input
Browse files Browse the repository at this point in the history
  • Loading branch information
mart2070 committed Aug 5, 2024
1 parent 787c125 commit ee72e8c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tdx-enhanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,33 @@
//ticket or task
let header = document.getElementById("thTicket_spnTitle") || document.querySelector("#upTaskHeader>h1")

//find calendar inputs when editing tickets/tasks
let calendars = document.querySelectorAll("input.hasDatepicker")
if (calendars) {
let originalFormat = "M/D/YYYY h:mm A";
let newFormat = "YYYY-MM-DDThh:mm";
[...calendars].forEach(calendar=>{
let date = moment(calendar.value,originalFormat)
let iso = date.format(newFormat)

let newCal = document.createElement("input")
newCal.id = `${calendar.id}-new`
newCal.classList = calendar.classList
newCal.type = "datetime-local"
newCal.value = iso

//convert to original format
newCal.addEventListener("input",event=>{
let parsedValue = moment(event.target.value,newFormat)
let parsedFormat = parsedValue.format(originalFormat)
calendar.value = parsedFormat
})

//old input still needs to exist for proper format conversion
calendar.style.display = "none"
calendar.parentElement.append(newCal)
});
}
//change tab title
if (header) {
let ticketTitle = header.childNodes[0].textContent
Expand Down

0 comments on commit ee72e8c

Please sign in to comment.