libs/core/dynamic-form/src/utils/form-layout/form-layout.utils.ts
Methods |
|
Static getFormsWithLayout | ||||||||
getFormsWithLayout(config: DfFormAndFields)
|
||||||||
Get the forms or the field with the default layout from the config. A form that extends the forms
Parameters :
Returns :
DfFormWithLayout[]
A list of forms with layout |
import { DfFormAndFields, DfFormLayout, DfFormWithLayout } from './form-layout.model';
const EMPTY_FORMS: DfFormWithLayout[] = [
{
layout: DfFormLayout.OneColumn,
fields: []
}
];
export class DfFormLayoutUtils {
/**
* Get the forms or the field with the default layout from the config.
* @param config Config, is not needed the whole config only a component that extends the configuration
* A form that extends the forms
* @return A list of forms with layout
*/
public static getFormsWithLayout(config: DfFormAndFields): DfFormWithLayout[] {
if (config?.fields && config?.forms) {
console.error(
'DfFormLayoutUtils: `fields` and `forms` was provided. Returning an empty form'
);
return EMPTY_FORMS;
} else if (config?.fields) {
return [
{
layout: config.defaultLayout || DfFormLayout.OneColumn,
fields: config.fields
}
];
} else if (config?.forms) {
return config.forms;
} else {
console.error(
'DfFormLayoutUtils: Neither `fields` or `forms` was provided. Returning an empty form'
);
return EMPTY_FORMS;
}
}
}