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