Add type conversion for input type 'number'

This commit is contained in:
Austin Smith
2025-10-20 18:55:00 -04:00
parent 0d9b4b6b22
commit ff44ef1b67

View File

@@ -35,17 +35,18 @@ class Field {
return this._name;
}
get value(): string | string[] | undefined {
get value(): string | string[] | number | number[] | undefined {
switch(this._type) {
case 'checkbox':
return (this._inputs as HTMLInputElement[]).filter(x => x.checked).map(x => x.value);
case 'radio':
return (this._inputs as HTMLInputElement[]).find(x => x.checked)?.value;
case 'number':
return (this._inputs.length > 1) ? this._inputs.map(x => Number(x.value)) : Number(this._inputs[0]!.value);
default:
case 'date':
case 'datatime-local':
case 'email':
case 'number':
case 'password':
case 'select':
case 'text':
@@ -185,7 +186,6 @@ export class Declaform extends HTMLElement {
const populateFields = (current: Record<string, any>, path: string) => {
for (const key of Object.keys(current)) {
const value = current[key];
console.log(`Visiting ${key} with value ${value}`)
const propPath = (path.length) ? `${path}.${key}` : key;
if (typeof value !== 'object') {
const fields = this.fields.filter(x => x.name === propPath);