-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
While working on the issue I mentioned in #303 we found another Problem when creating disabled controls.
When passing a disabled control like this:
public form = createForm<MyForm>({
...,
formControls: {
name: new FormControl({ value: '', disabled: true }),
}
});The FormGroup that the name control is added to is being set to "enabled" because the disabled$ observable is defaulted to of(false) which causes the formGroup.enable call here:
https://github.com/cloudnc/ngx-sub-form/blob/43dede0015975db59333abbc185964a15acb4262/projects/ngx-sub-form/src/lib/create-form.ts#L238C13-L238C13
This resets all disabled states that I initially pass to the FormControls.
I found two workarounds:
- Provide
disabled$as a never emitting observable:
public form = createForm<MyForm>({
...,
disabled$: new Observable<boolean>(),
formControls: {
name: new FormControl({ value: '', disabled: true }),
}
});- Set the disabled state again in the constructor:
constructor() {
this.form.formGroup.controls.name.disable();
}This behaviour was unexpected as the new API also handles the default values via the FormControl constructors.
acadianaapps
Metadata
Metadata
Assignees
Labels
No labels