Skip to content

Commit

Permalink
fix(json-schema): do not replace expression properties if required fi… (
Browse files Browse the repository at this point in the history
#2839)

Co-authored-by: Daniel Pohl <daniel.pohl@maximago.de>
Co-authored-by: Abdellatif Ait boudad <a.aitboudad@gmail.com>
  • Loading branch information
3 people committed May 16, 2021
1 parent 103c04a commit 56ee55c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/core/json-schema/src/formly-json-schema.service.spec.ts
Expand Up @@ -387,6 +387,32 @@ describe('Service: FormlyJsonschema', () => {
fixture.detectChanges();
expect(childField.templateOptions.required).toBeTruthy();
});

it('should not kill other expressionProperties', () => {
const {field} = renderComponent(JSON.parse(`{
"schema": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string",
"widget": {
"formlyConfig": {
"expressionProperties": {
"templateOptions.readonly": "model.readonly"
}
}
}
}
}
}
}`));

const childField = field.fieldGroup[0];
expect(childField.expressionProperties['templateOptions.readonly']).toEqual('model.readonly');
});
});

describe('dependencies', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/core/json-schema/src/formly-json-schema.service.ts
Expand Up @@ -154,7 +154,8 @@ export class FormlyJsonschema {
(Array.isArray(schema.required) && schema.required.indexOf(property) !== -1)
|| propDeps[property]
) {
f.expressionProperties = {
f.expressionProperties = {
...(f.expressionProperties || {}),
'templateOptions.required': (m, s, f) => {
const { model, templateOptions: { required } } = f.parent ? f.parent : { templateOptions: {} } as any;
if (!model && !required) {
Expand Down

0 comments on commit 56ee55c

Please sign in to comment.