Skip to content

Commit

Permalink
fix(core): ensure disabled prop is working for field without key (#3665)
Browse files Browse the repository at this point in the history
fix #3657
  • Loading branch information
aitboudad committed May 1, 2023
1 parent 78ec05e commit 1dd5c6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/core/src/lib/extensions/field-form/field-form.spec.ts
Expand Up @@ -210,6 +210,15 @@ describe('FieldFormExtension', () => {
});

describe('props disabled state', () => {
it('should disable field without key', () => {
const field = buildField({
props: { disabled: true },
});

const control = field.formControl;
expect(control.disabled).toBeTrue();
});

it('should disable sub-fields when parent is disabled', () => {
const field = buildField({
key: 'address',
Expand Down
5 changes: 4 additions & 1 deletion src/core/src/lib/extensions/field-form/field-form.ts
Expand Up @@ -61,7 +61,10 @@ export class FieldFormExtension implements FormlyExtension {
control = new FormGroup({}, controlOptions);
} else {
const value = hasKey(field) ? getFieldValue(field) : field.defaultValue;
control = new FormControl({ value, disabled: false }, { ...controlOptions, initialValueIsDefault: true });
control = new FormControl(
{ value, disabled: !!field.props.disabled },
{ ...controlOptions, initialValueIsDefault: true },
);
}
}

Expand Down

0 comments on commit 1dd5c6e

Please sign in to comment.