diff --git a/packages/crayons-extended/custom-objects/src/components/form-builder/components/field-editor.tsx b/packages/crayons-extended/custom-objects/src/components/form-builder/components/field-editor.tsx index 63d848948..ff8945222 100644 --- a/packages/crayons-extended/custom-objects/src/components/form-builder/components/field-editor.tsx +++ b/packages/crayons-extended/custom-objects/src/components/form-builder/components/field-editor.tsx @@ -1053,7 +1053,15 @@ export class FieldEditor { let strInternalName = ''; let boolInternalNameUpdated = false; - if ((!this.isInternalNameEdited && this.isNewField) || field.isNew) { + const objMaxLimitFieldInternalName = getMaxLimitProperty( + this.productName, + 'maxInternalNameChars' + ); + if ( + ((!this.isInternalNameEdited && this.isNewField) || field.isNew) && + objMaxLimitFieldInternalName && + strInputValue.length <= objMaxLimitFieldInternalName.count + ) { strInternalName = deriveInternalNameFromLabel(strInputValue); boolInternalNameUpdated = true; } @@ -1088,8 +1096,7 @@ export class FieldEditor { 'maxInternalNameChars' ); if ( - !this.internalNameWarningMessage && - this.internalNameWarningMessage !== '' && + this.internalNameWarningMessage === '' && objMaxLimitFieldName && strInternalName.length >= objMaxLimitFieldName.count ) { @@ -1099,6 +1106,8 @@ export class FieldEditor { count: objMaxLimitFieldName.count, } ); + } else { + this.internalNameWarningMessage = ''; } if (!this.isInternalNameEdited || field.isNew) { diff --git a/packages/crayons-extended/custom-objects/src/components/form-builder/utils/form-builder-utils.spec.ts b/packages/crayons-extended/custom-objects/src/components/form-builder/utils/form-builder-utils.spec.ts index 2c4bcfdfd..975a2c7ef 100644 --- a/packages/crayons-extended/custom-objects/src/components/form-builder/utils/form-builder-utils.spec.ts +++ b/packages/crayons-extended/custom-objects/src/components/form-builder/utils/form-builder-utils.spec.ts @@ -17,6 +17,7 @@ import { buildChoicesFromText, getParentId, getChildChoices, + getMaximumLimitsConfig, } from './form-builder-utils'; describe('getFieldBasedOnLevel', () => { @@ -586,3 +587,47 @@ describe('getChildChoices', () => { }); }); }); +describe('getMaximumLimitsConfig', () => { + it('returns maximum limits config for CUSTOM_OBJECTS', () => { + const formMapper = { + CUSTOM_OBJECTS: { + maximumLimits: { + DECIMAL: { count: 20, message: 'maximumLimits.fields' }, + }, + }, + }; + const result = getMaximumLimitsConfig(); + expect(result.DECIMAL.count).toEqual( + formMapper.CUSTOM_OBJECTS.maximumLimits.DECIMAL.count + ); + }); + + it('returns maximum limits config for Internal Name', () => { + const formMapper = { + CUSTOM_OBJECTS: { + maximumLimits: { + maxInternalNameChars: { + count: 50, + message: 'maximumLimits.maxCharsWarning', + }, + }, + }, + }; + const result = getMaximumLimitsConfig(); + expect(result.maxInternalNameChars.count).toEqual( + formMapper.CUSTOM_OBJECTS.maximumLimits.maxInternalNameChars.count + ); + }); + + it('returns null when productName is not found in formMapper', () => { + const formMapper = { + OTHER_PRODUCT: { + maximumLimits: { + DECIMAL: { count: 20, message: 'maximumLimits.fields' }, + }, + }, + }; + const result = getMaximumLimitsConfig('OTHER_PRODUCT'); + expect(result).toBeNull(); + }); +});