Skip to content

Commit

Permalink
revert: disable control when parent is disabled (#1539)
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad committed Apr 17, 2019
1 parent 5916765 commit 9f033d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
19 changes: 1 addition & 18 deletions src/core/src/lib/extensions/field-form/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('registerControl', () => {
expect(field.formControl.parent).not.toBeNull();
});

it('should take account of model changes', () => {
it('should take account of model changes', () => {
const field = {
key: '0',
formControl: new FormControl(),
Expand All @@ -62,23 +62,6 @@ describe('registerControl', () => {
registerControl(field);
expect(field.formControl.value).toEqual('test');
});

it('should disable control if parent is disabled', () => {
const field = {
key: '0',
formControl: new FormControl(),
parent: {
model: { '0': 'test' },
formControl: new FormGroup({}),
},
};

field.parent.formControl.disable();

registerControl(field);
expect(field.formControl.parent).not.toBeNull();
expect(field.formControl.disabled).toBeTruthy();
});
});

describe('unregisterControl', () => {
Expand Down
18 changes: 8 additions & 10 deletions src/core/src/lib/extensions/field-form/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ export function registerControl(field: FormlyFieldConfig, control?: any) {
control.disable();
}

Object.defineProperty(field.templateOptions, 'disabled', {
get: () => !field.formControl.enabled,
set: (value: boolean) => value ? field.formControl.disable() : field.formControl.enable(),
enumerable: true,
configurable: true,
});
if (delete field.templateOptions.disabled) {
Object.defineProperty(field.templateOptions, 'disabled', {
get: () => !field.formControl.enabled,
set: (value: boolean) => value ? field.formControl.disable() : field.formControl.enable(),
enumerable: true,
configurable: true,
});
}
}

let parent = field.parent.formControl as FormGroup;
Expand Down Expand Up @@ -62,10 +64,6 @@ export function registerControl(field: FormlyFieldConfig, control?: any) {
}
const key = paths[paths.length - 1];
if (parent.get([key]) !== control) {
if (parent.disabled && control.enabled) {
control.disable();
}

parent.setControl(key, control);
}
}

0 comments on commit 9f033d4

Please sign in to comment.