Commit e15fa45232e39e18f7bb7fcd209402ea5f0819e6
1 parent
3400ba2f
Added form fields trim to add/edit entity
Showing
1 changed file
with
15 additions
and
1 deletions
@@ -23,6 +23,7 @@ import { AppState } from '@core/core.state'; | @@ -23,6 +23,7 @@ import { AppState } from '@core/core.state'; | ||
23 | import { EntityAction } from '@home/models/entity/entity-component.models'; | 23 | import { EntityAction } from '@home/models/entity/entity-component.models'; |
24 | import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; | 24 | import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; |
25 | import { PageLink } from '@shared/models/page/page-link'; | 25 | import { PageLink } from '@shared/models/page/page-link'; |
26 | +import { isObject, isString } from '@core/utils'; | ||
26 | 27 | ||
27 | // @dynamic | 28 | // @dynamic |
28 | @Directive() | 29 | @Directive() |
@@ -115,7 +116,20 @@ export abstract class EntityComponent<T extends BaseData<HasId>, | @@ -115,7 +116,20 @@ export abstract class EntityComponent<T extends BaseData<HasId>, | ||
115 | } | 116 | } |
116 | 117 | ||
117 | prepareFormValue(formValue: any): any { | 118 | prepareFormValue(formValue: any): any { |
118 | - return formValue; | 119 | + return this.deepTrim(formValue); |
120 | + } | ||
121 | + | ||
122 | + private deepTrim(obj: object): object { | ||
123 | + return Object.keys(obj).reduce((acc, curr) => { | ||
124 | + if (isString(obj[curr])) { | ||
125 | + acc[curr] = obj[curr].trim(); | ||
126 | + } else if (isObject(obj[curr])) { | ||
127 | + acc[curr] = this.deepTrim(obj[curr]) | ||
128 | + } else { | ||
129 | + acc[curr] = obj[curr]; | ||
130 | + } | ||
131 | + return acc; | ||
132 | + }, {}); | ||
119 | } | 133 | } |
120 | 134 | ||
121 | protected setEntitiesTableConfig(entitiesTableConfig: C) { | 135 | protected setEntitiesTableConfig(entitiesTableConfig: C) { |