diff --git a/generators/react/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.tsx.ejs b/generators/react/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.tsx.ejs index 29b511ab9506..fd6fdd63717a 100644 --- a/generators/react/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.tsx.ejs +++ b/generators/react/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_-update.tsx.ejs @@ -39,6 +39,7 @@ import { convertDateTimeFromServer, convertDateTimeToServer, displayDefaultDateT <%_ if (relationships.filter(e => e.relationshipManyToMany) !== undefined) { _%> import { mapIdList } from 'app/shared/util/entity-utils'; <%_ } _%> +import { prepareValuesToSave } from 'app/shared/util/entity-utils'; import { useAppDispatch, useAppSelector } from 'app/config/store'; <%_ @@ -159,7 +160,7 @@ _%> const entity = { ...<%= entityInstance %>Entity, - ...values, + ...prepareValuesToSave(values, <%= entityInstance %>Entity), <%_ manyToManyOwners.forEach(rel => { _%> <%= rel.relationshipFieldNamePlural %>: mapIdList(values.<%= rel.relationshipFieldNamePlural %>), <%_ }) _%> diff --git a/generators/react/templates/src/main/webapp/app/shared/util/entity-utils.spec.ts.ejs b/generators/react/templates/src/main/webapp/app/shared/util/entity-utils.spec.ts.ejs index b8554923834d..11541824147c 100644 --- a/generators/react/templates/src/main/webapp/app/shared/util/entity-utils.spec.ts.ejs +++ b/generators/react/templates/src/main/webapp/app/shared/util/entity-utils.spec.ts.ejs @@ -18,7 +18,7 @@ -%> -import { cleanEntity, mapIdList } from './entity-utils'; +import { cleanEntity, mapIdList, prepareValuesToSave } from './entity-utils'; describe('Entity utils', () => { describe('cleanEntity', () => { @@ -73,4 +73,31 @@ describe('Entity utils', () => { expect(mapIdList(ids)).toEqual([]); }); }); + + describe('prepareValuesToSave', () => { + it("should convert string type to number type if the property type is number", () => { + interface ITestEntity { + id?: number; + name?: string; + age?: number; + }; + const entity: ITestEntity = { + id: 1, + name: 'oldName', + age: 20, + }; + const values = { + id: 1, + name: 'newTest', + age: '21', + }; + const result = { + id: 1, + name: 'newTest', + age: 21, + }; + + expect(prepareValuesToSave(values, entity)).toEqual(result); + }); + }); }); diff --git a/generators/react/templates/src/main/webapp/app/shared/util/entity-utils.ts.ejs b/generators/react/templates/src/main/webapp/app/shared/util/entity-utils.ts.ejs index 82e554f6688f..ae1acc47fe60 100644 --- a/generators/react/templates/src/main/webapp/app/shared/util/entity-utils.ts.ejs +++ b/generators/react/templates/src/main/webapp/app/shared/util/entity-utils.ts.ejs @@ -60,3 +60,13 @@ export const overridePaginationStateWithQueryParams = (paginationBaseState: IPag } return sortedPaginationState; }; + +export const prepareValuesToSave = (values, entity) => { + const result = { ...values }; + for (const property in values) { + if (typeof entity[property] === 'number' && typeof values[property] === 'string') { + result[property] = parseFloat(values[property]); + } + } + return result; +};