Skip to content

Commit

Permalink
[frontend] attribute variable name no space validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Archidoit committed Jan 10, 2025
1 parent f74d878 commit 92d4acd
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const WidgetAttributesInput: FunctionComponent<WidgetCreationAttributesProps> =
{ attribute: 'objectMarking.definition', label: 'Marking' },
];
const attributesValidation = () => Yup.object().shape({
variableName: Yup.string().required(t_i18n('This field is required')),
variableName: Yup.string()
.test('no-space', 'This field cannot contain spaces', (v) => {
return !v?.includes(' ');
})
.required(t_i18n('This field is required')),
});
const setFieldValue = (attribute: string | null, field: string, newValue: string) => {
const newColumns = value.map((c) => (c.attribute === attribute ? {
Expand Down Expand Up @@ -75,13 +79,13 @@ const WidgetAttributesInput: FunctionComponent<WidgetCreationAttributesProps> =
key={column.attribute}
initialValues={{
variableName: column.variableName ?? column.attribute,
label: column.variableName ?? '',
label: column.label ?? '',
attribute: column.attribute,
}}
validationSchema={attributesValidation()}
onSubmit={() => {}}
>
{() => (
{({ isValid }) => (
<Form>
<Field
component={TextField}
Expand All @@ -95,14 +99,14 @@ const WidgetAttributesInput: FunctionComponent<WidgetCreationAttributesProps> =
name="label"
label={t_i18n('Label')}
style={{ marginTop: 20, marginLeft: 10, width: 220 }}
onChange={(n: string, v: string) => setFieldValue(column.attribute, n, v)}
onChange={isValid ? (n: string, v: string) => setFieldValue(column.attribute, n, v) : undefined}
/>
<Field
component={TextField}
name="variableName"
label={t_i18n('Variable name')}
style={{ marginTop: 20, marginLeft: 10, width: 220 }}
onChange={(n: string, v: string) => setFieldValue(column.attribute, n, v)}
onChange={isValid ? (n: string, v: string) => setFieldValue(column.attribute, n, v) : undefined}
/>
</Form>
)}
Expand Down

0 comments on commit 92d4acd

Please sign in to comment.