1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-02-24 15:27:43 +01:00

feat: Aggiunto campo per precedenza dei campi

This commit is contained in:
Maicol Battistini 2022-01-03 13:31:37 +01:00
parent 552c69cce2
commit 080d70bd49
No known key found for this signature in database
GPG Key ID: 4FDB0F87CDB1D34A

View File

@ -59,10 +59,15 @@ export class RecordsPage extends Page {
dialogs: Children[]; dialogs: Children[];
recordDialogMaxWidth: string | number = '75%'; recordDialogMaxWidth: string | number = 'auto';
model: typeof Model; model: typeof Model;
/**
* What fields should take precedence when saving the record
*/
fieldsPrecedence: string[] = [];
async oninit(vnode) { async oninit(vnode) {
super.oninit(vnode); super.oninit(vnode);
const response = await this.model.all(); const response = await this.model.all();
@ -193,7 +198,7 @@ export class RecordsPage extends Page {
id: field.id ?? fieldIndex, id: field.id ?? fieldIndex,
name: field.name ?? field.id ?? fieldIndex, name: field.name ?? field.id ?? fieldIndex,
'data-default-value': field.value ?? (field.selected ?? '') 'data-default-value': field.value ?? (field.selected ?? '')
})} }, this.getFieldBody(field))}
</mwc-layout-grid-cell> </mwc-layout-grid-cell>
)) ))
.toArray(); .toArray();
@ -285,8 +290,13 @@ export class RecordsPage extends Page {
// eslint-disable-next-line new-cap // eslint-disable-next-line new-cap
const instance: Model = new this.model(); const instance: Model = new this.model();
form.find('text-field, text-area, material-select') const fields = form.find('text-field, text-area, material-select');
.each((index, field: TextField | TextArea) => { for (const fieldName of this.fieldsPrecedence) {
const field = fields.find(`#${fieldName}`);
instance[field.attr('id')] = field.val();
}
fields.each((index, field: TextField | TextArea) => {
instance[field.id] = field.value; instance[field.id] = field.value;
}); });
@ -328,11 +338,31 @@ export class RecordsPage extends Page {
case 'select': case 'select':
return 'material-select'; return 'material-select';
/* Case 'checkbox': /* Case 'checkbox':
return Checkbox;
case 'radio': case 'radio':
return Radio; */ return Radio; */
default: default:
return 'text-field'; return 'text-field';
} }
} }
getFieldBody(field: TextFieldT | TextAreaT | SelectT) {
switch (field.type) {
case 'select':
return (
<>
{field.options.map((option: { value: string, label: string }) => {
return (
<mwc-list-item key={option} value={option.value}>{option.label}</mwc-list-item>
);
})}
</>
);
case 'checkbox':
return '';
case 'radio':
return '';
default:
return '';
}
}
} }