Skip to content

Commit

Permalink
fixed required property application on multilang fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mmadariaga committed Jan 29, 2024
1 parent 5dda194 commit 4a5e49e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion demo/src/entities/Feature/Feature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const properties: FeatureProperties = {
name: {
label: _('Name'),
multilang: true,
required: true,
required: false,
},
};

Expand Down
13 changes: 11 additions & 2 deletions library/src/entities/DefaultEntityBehavior/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const validator: EntityValidator = (
continue;
}

if (!validateEmbeddables && idx.indexOf('.') > 0) {
const isSubproperty = idx.indexOf('.') > 0;
if (!validateEmbeddables && isSubproperty) {
continue;
}

Expand All @@ -53,7 +54,15 @@ const validator: EntityValidator = (
continue;
}

const required = (properties[idx] as ScalarProperty)?.required;
let isRootPropertyRequired: undefined | boolean;
if (isSubproperty) {
const parentIdx = idx.substring(0, idx.lastIndexOf('.'));
const rootProperty = properties[parentIdx];
isRootPropertyRequired = rootProperty?.required;
}

const required =
isRootPropertyRequired ?? (properties[idx] as ScalarProperty)?.required;
const pattern: RegExp | undefined = (properties[idx] as ScalarProperty)
?.pattern;
if (pattern && !(values[idx] + '').match(pattern)) {
Expand Down
3 changes: 2 additions & 1 deletion library/src/services/form/Field/Multilang.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const Multilang: React.FC<MultilangPropsInterface> = (props): JSX.Element => {
const property = properties[name] as ScalarProperty;
const multiline = property.format === 'textarea';
const required =
rootProperty.required || property?.required || false;
rootProperty.required ?? property?.required ?? false;

const touched =
formik?.touched[_columnName] &&
(formik?.touched[_columnName] as Record<string, boolean>)[locale];
Expand Down

0 comments on commit 4a5e49e

Please sign in to comment.