Commit b6aba1c40992df2e00bca621cfb0803aae78ebfd

Authored by Igor Kulikov
Committed by GitHub
2 parents b57d17f1 e15fa452

Merge pull request #3029 from vvlladd28/improvement/entity/trim-fields

[3.0] Added form fields trim to add/edit entity
... ... @@ -23,6 +23,7 @@ import { AppState } from '@core/core.state';
23 23 import { EntityAction } from '@home/models/entity/entity-component.models';
24 24 import { EntityTableConfig } from '@home/models/entity/entities-table-config.models';
25 25 import { PageLink } from '@shared/models/page/page-link';
  26 +import { isObject, isString } from '@core/utils';
26 27
27 28 // @dynamic
28 29 @Directive()
... ... @@ -115,7 +116,20 @@ export abstract class EntityComponent<T extends BaseData<HasId>,
115 116 }
116 117
117 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 135 protected setEntitiesTableConfig(entitiesTableConfig: C) {
... ...