Simplified form
Change-Id: Ib4b17823be86e18bd5e83679cde7fc95a4f8bac1
diff --git a/src/app/core/form/form-helpers.ts b/src/app/core/form/form-helpers.ts
index 0677cbd..d2d7373 100644
--- a/src/app/core/form/form-helpers.ts
+++ b/src/app/core/form/form-helpers.ts
@@ -1,10 +1,11 @@
-import * as _ from 'lodash';
import {IXosConfigHelpersService} from '../services/helpers/config.helpers';
+import {IXosFormInput} from './form';
export interface IXosFormHelpersService {
_getFieldFormat(value: any): string;
parseModelField(fields: any): any[];
buildFormStructure(modelField: any[], customField: any[], model: any, order: string[]): any;
+ buildFormData(fields: IXosFormInput[], model: any): any;
}
export class XosFormHelpers {
@@ -54,53 +55,5 @@
return typeof value;
};
-
- public buildFormStructure = (modelField, customField, model, order) => {
- // TODO take an array as input
- // NOTE do we want to support auto-generated forms??
- // We can take that out of this component and autogenerate the config somewhere else
- const orderedForm = {};
-
- modelField = angular.extend(modelField, customField);
- customField = customField || {};
-
- if (order) {
- _.each(order, function (key: string) {
- orderedForm[key] = {};
- });
- }
-
- _.each(Object.keys(modelField), (f) => {
-
- orderedForm[f] = {
- label: (customField[f] && customField[f].label) ? `${customField[f].label}:` : this.ConfigHelpers.toLabel(f),
- type: (customField[f] && customField[f].type) ? customField[f].type : this._getFieldFormat(model[f]),
- validators: (customField[f] && customField[f].validators) ? customField[f].validators : {},
- hint: (customField[f] && customField[f].hint) ? customField[f].hint : '',
- };
-
- if (customField[f] && customField[f].options) {
- orderedForm[f].options = customField[f].options;
- }
- if (customField[f] && customField[f].properties) {
- orderedForm[f].properties = customField[f].properties;
- }
- if (orderedForm[f].type === 'date') {
- model[f] = new Date(model[f]);
- }
-
- if (orderedForm[f].type === 'number') {
- model[f] = parseInt(model[f], 10);
- }
- });
-
- return orderedForm;
- };
-
- public parseModelField = (fields) => {
- return _.reduce(fields, (form, f) => {
- form[f] = {};
- return form;
- }, {});
}
-}
+