From 6964103c253675cdfccc5662577795452ea96380 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Wed, 4 Jan 2023 14:55:12 -0500 Subject: [PATCH] interface.js: add number input --- scripts/interface.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/interface.js b/scripts/interface.js index cf1c15a..bc678d6 100644 --- a/scripts/interface.js +++ b/scripts/interface.js @@ -143,6 +143,17 @@ class Form extends InterfaceElement { return this.appendElement(new FormElement(params)); } + createNumberInput(params) { + params.tag = document.createElement("input"); + params.tag.setAttribute("type", "number"); + dataTypeSupports(params, ["number"]); + if (params.maxValue !== undefined) params.tag.max = params.maxValue; + if (params.minValue !== undefined) params.tag.min = params.minValue; + if (params.step !== undefined) params.tag.step = params.step; + if (params.required !== undefined) params.tag.required = params.required; + return this.appendElement(new FormElement(params)); + } + createTextArea(params) { params.tag = document.createElement("textarea"); dataTypeSupports(params, ["plaintext", "b64", "json-b64"]); @@ -232,6 +243,12 @@ class FormElement extends InterfaceElement { get value() { this.clearAlerts(); switch (this.dataType) { + case "number": + if (this.handle.checkValidity() == false) { + this.alertBox("alert-error", this.handle.validationMessage); + return undefined; + } + return Number(this.handle.value); case "plaintext": return this.handle.value; case "b64": @@ -263,6 +280,7 @@ class FormElement extends InterfaceElement { } set value(x) { switch (this.dataType) { + case "number": case "plaintext": this.handle.value = x; break;