Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export default {
'app.maxLength': 'Maximum length',
'app.regexp': 'Regular expression',
'app.enumeratorStaticItems': 'Elements',
'app.enumeratorStaticItems.help': 'Insert a configuration like \'lable1,lable2,lable3\'',
'app.enumeratorStaticItems.help': 'Insert a configuration like \'label1,label2,label3\'',
'app.enumeratorStaticItemsMap.help': 'Insert a configuration like \'key1=value1,key2=value2,key3=value3\'',
'app.enumeratorStaticItemsSeparator': 'Separator',
'app.enumeratorExtractorBean': 'Extractor bean name',
Expand Down Expand Up @@ -973,6 +973,7 @@ export default {
'app.pages.friendlyCodeHelp': 'URL slug for the page. You can insert a max of 100 characters, lowercase letters, including numbers or \'_\' special character.',
'validateForm.friendlyCode': 'Friendly Code must be lowercase letters, including numbers or \'_\' special character.',
'validateForm.friendlyCodeUnique': 'Friendly Code must be unique for all languages.',
'validateForm.specialCharacter': 'Please choose a single special character from this list: !@#%&_=,:;`',
'app.startTutorial': 'Start Welcome Wizard',
'emailConfig.smtpServer': 'SMTP Server',
'emailConfig.senderMgmt': 'Sender Management',
Expand Down
1 change: 1 addition & 0 deletions src/locales/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -1600,5 +1600,6 @@ export default {
'user.authority.addNew': 'Aggiungi nuova Autorizzazione',
'componentRepository.refreshBundleVersions': 'Aggiorna le versioni disponibili del bundle',
'componentRepository.bundle.installVersionsRefreshed': 'Aggiornato',
'validateForm.specialCharacter': 'Si prega di scegliere un singolo carattere speciale da questo elenco: !@#%&_=,:;`',
},
};
1 change: 1 addition & 0 deletions src/locales/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -1022,5 +1022,6 @@ export default {
'user.authority.addNew': 'Adicionar nova Autorização',
'componentRepository.refreshBundleVersions': 'Atualizar as versões disponíveis do pacote',
'componentRepository.bundle.installVersionsRefreshed': 'Atualizado',
'validateForm.specialCharacter': 'Escolha um único caractere especial desta lista: !@#%&_=,:;`',
},
};
29 changes: 28 additions & 1 deletion src/ui/common/attributes/AttributeEnumSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ export const element = value =>
(value && !/^[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)*$/i.test(value)
? <FormattedMessage id="validateForm.element" /> : undefined);

const specialCharRegex = /^[!@#%&_=,:;`]$/;


const specialSymbolValidator = (value) => {
if (value && !value.match(specialCharRegex)) {
return <FormattedMessage id="validateForm.specialCharacter" />;
}
return undefined;
};


export const separatorValidator = (value, allValues) => {
if (allValues.enumeratorStaticItemsSeparator && value &&
allValues.enumeratorStaticItemsSeparator.match(specialCharRegex)) {
const regexp =
new
RegExp(`^([^${allValues.enumeratorStaticItemsSeparator}]+)(${allValues.enumeratorStaticItemsSeparator}([^${allValues.enumeratorStaticItemsSeparator}])+)*$`);
if (!regexp.test(value)) {
return <FormattedMessage id="validateForm.element" />;
}
return undefined;
}
return undefined;
};


const msgs = defineMessages({
help: {
id: 'app.enumeratorStaticItems.help',
Expand Down Expand Up @@ -41,14 +67,15 @@ const AttributeEnumSettings = ({ intl, enumeratorExtractorBeans, mode }) => {
<FormLabel labelId="app.enumeratorStaticItems" required />
}
placeholder={intl.formatMessage(msgs.help)}
validate={[required, element]}
validate={[required, separatorValidator]}
/>
<Field
component={RenderTextInput}
name="enumeratorStaticItemsSeparator"
label={
<FormLabel labelId="app.enumeratorStaticItemsSeparator" />
}
validate={[specialSymbolValidator]}
/>
{
mode === MODE_ADD ?
Expand Down
4 changes: 2 additions & 2 deletions test/ui/common/attributes/AttributeEnumSettings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import 'test/enzyme-init';
import { mount } from 'enzyme';
import AttributeEnumSettings, { element as elementValidation } from 'ui/common/attributes/AttributeEnumSettings';
import AttributeEnumSettings, { separatorValidator } from 'ui/common/attributes/AttributeEnumSettings';
import RenderTextInput from 'ui/common/form/RenderTextInput';
import RenderSelectInput from 'ui/common/form/RenderSelectInput';
import { required } from '@entando/utils';
Expand Down Expand Up @@ -30,7 +30,7 @@ describe('AttributeEnumSettings', () => {
expect(element.exists()).toBe(true);
const props = element.props();
expect(props).toHaveProperty('component', RenderTextInput);
expect(props).toHaveProperty('validate', [required, elementValidation]);
expect(props).toHaveProperty('validate', [required, separatorValidator]);
});

it('has a enumeratorExtractorBean select field', () => {
Expand Down