mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
fix: 🐛 Fix opzioni async nelle select
This commit is contained in:
@@ -11,6 +11,7 @@ import type {
|
|||||||
Vnode,
|
Vnode,
|
||||||
VnodeDOM
|
VnodeDOM
|
||||||
} from 'mithril';
|
} from 'mithril';
|
||||||
|
import {sync as render} from 'mithril-node-render';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IModel,
|
IModel,
|
||||||
@@ -160,7 +161,8 @@ export class RecordsPage extends Page {
|
|||||||
dialog
|
dialog
|
||||||
// eslint-disable-next-line sonarjs/no-duplicate-string
|
// eslint-disable-next-line sonarjs/no-duplicate-string
|
||||||
.find('text-field, text-area, material-select')
|
.find('text-field, text-area, material-select')
|
||||||
.each((index, field) => {
|
.each(async (index, field) => {
|
||||||
|
field.innerHTML = await this.getFieldBody(field as HTMLFormElement);
|
||||||
(field as HTMLInputElement).value = this.getModelValue(instance, field.id) as string;
|
(field as HTMLInputElement).value = this.getModelValue(instance, field.id) as string;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -227,8 +229,7 @@ export class RecordsPage extends Page {
|
|||||||
name: field.name ?? field.id ?? fieldIndex,
|
name: field.name ?? field.id ?? fieldIndex,
|
||||||
'data-default-value':
|
'data-default-value':
|
||||||
field.value ?? (field as SelectT).selected ?? ''
|
field.value ?? (field as SelectT).selected ?? ''
|
||||||
},
|
}
|
||||||
this.getFieldBody(field)
|
|
||||||
)}
|
)}
|
||||||
</mwc-layout-grid-cell>
|
</mwc-layout-grid-cell>
|
||||||
))
|
))
|
||||||
@@ -310,8 +311,10 @@ export class RecordsPage extends Page {
|
|||||||
fab.on('click', () => {
|
fab.on('click', () => {
|
||||||
form
|
form
|
||||||
.find('text-field, text-area, material-select')
|
.find('text-field, text-area, material-select')
|
||||||
.each((index, field) => {
|
.each(async (index, field) => {
|
||||||
(field as HTMLInputElement).value = $(field).data('default-value') as string;
|
field.innerHTML = await this.getFieldBody(field as HTMLFormElement);
|
||||||
|
(field as HTMLInputElement).value = $(field)
|
||||||
|
.data('default-value') as string;
|
||||||
});
|
});
|
||||||
dialog.find('mwc-button[type="submit"] mwc-circular-progress').hide();
|
dialog.find('mwc-button[type="submit"] mwc-circular-progress').hide();
|
||||||
dialog.find('mwc-button#delete-button').hide();
|
dialog.find('mwc-button#delete-button').hide();
|
||||||
@@ -407,18 +410,27 @@ export class RecordsPage extends Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getFieldBody(field: FieldT | TextFieldT | TextAreaT | SelectT) {
|
async getFieldBody(field: HTMLFormElement) {
|
||||||
const list = [];
|
const list = [];
|
||||||
|
|
||||||
switch (field.type) {
|
switch (field.type ?? field.getAttribute('type')) {
|
||||||
case 'select':
|
case 'select':
|
||||||
// @ts-ignore
|
// eslint-disable-next-line no-case-declarations
|
||||||
for (const option of (field as SelectT).options) {
|
const section = this.sections.find((value) => field.id in value.fields);
|
||||||
list.push(
|
// eslint-disable-next-line no-case-declarations
|
||||||
|
let {options} = (section?.fields as Record<string, SelectT>)[field.id];
|
||||||
|
if (options instanceof Promise) {
|
||||||
|
options = await options;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options) {
|
||||||
|
for (const option of options) {
|
||||||
|
list.push(render(
|
||||||
<mwc-list-item key={option.value} value={option.value}>
|
<mwc-list-item key={option.value} value={option.value}>
|
||||||
{option.label}
|
{option.label}
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
);
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -433,9 +445,9 @@ export class RecordsPage extends Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (field.icon) {
|
if (field.icon) {
|
||||||
list.push(<Mdi icon={field.icon} slot="icon" />);
|
list.push(render(<Mdi icon={(field as FieldT).icon} slot="icon"/>));
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list.join('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user