Skip to content

Commit

Permalink
fix datetime-local inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
benStre committed Oct 31, 2024
1 parent 995f3c6 commit 6532830
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions datex-bindings/dom-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ export class DOMUtils {
else if (type.matchesType(Datex.Type.std.boolean)) element.addEventListener(event, () => this.handleSetVal(value, inputElement, inputElement.value, "boolean"))
else if (type.matchesType(Datex.Type.std.void) || type.matchesType(Datex.Type.std.null)) {console.warn("setting value attribute to " + type, element)}
else if (type.matchesType(Datex.Type.std.time)) element.addEventListener(event, () => {
handleSetVal(new Time((element as unknown as HTMLInputElement).valueAsDate ?? new Date((element as unknown as HTMLInputElement).value+"Z")))
handleSetVal(new Time((element as unknown as HTMLInputElement).valueAsDate ?? new Date((element as unknown as HTMLInputElement).value)))
})
else throw new Error("The type "+type+" is not supported for the '"+attr+"' attribute of the <"+element.tagName.toLowerCase()+"> element");
}
Expand Down Expand Up @@ -789,7 +789,7 @@ export class DOMUtils {
if (root_path==undefined) return val?.toString?.() ?? ""
else if (typeof val == "string" && (val.startsWith("./") || val.startsWith("../"))) return new URL(val, root_path).toString();
else if (val instanceof Date) {
if ((element as HTMLInputElement).type == "datetime-local") return val.toISOString().slice(0,-8);
if ((element as HTMLInputElement).type == "datetime-local") return new Date(val.getTime() + new Date().getTimezoneOffset() * -60 * 1000).toISOString().slice(0,-8);
else return val.toISOString().slice(0,10);
}
else return val?.toString?.() ?? ""
Expand Down

0 comments on commit 6532830

Please sign in to comment.