udos86 / ng-dynamic-forms

Rapid form development library for Angular

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Relations - disable/enable on some form controls is broken

ticxx opened this issue · comments

commented

I'm submitting a


[x] Bug / Regression
[ ] Feature Request / Proposal

I'm using


NG Dynamic Forms Version: `12.0.9`

[ ] Basic UI
[ ] Bootstrap UI  
[ ] Foundation UI
[ ] Ionic UI
[x] Kendo UI
[ ] Material  
[x] NG Bootstrap
[x] Prime NG

Description

unfortunately there is a regression concerning the issue #993 Again many form controls do not behave as expected.
One possibility to solve the issue is to alter the DISABLED_MATCHER:

export const DISABLED_MATCHER: DynamicFormControlMatcher = {
    match: MATCH_DISABLED,
    opposingMatch: MATCH_ENABLED,
    onChange(hasMatch, model, control: FormControl, injector ) {
        model.disabled = hasMatch;
        injector.get(DynamicFormService).detectChanges();
    }
};

furthermore, it is not a good idea to use the alternative declaration:

<form [formGroup]="formGroup">

    <dynamic-material-form-control *ngFor="let controlModel of formModel"
                                   [group]="formGroup"
                                   [model]="controlModel"></dynamic-material-form-control>
</form>

in this case the ngOnInit in DynamicFormComponent is not triggered and so this.componentService.getForms() in DynamicFormService.detectChanges() may return an empty array ...

thanks for all your work!!!

commented

Unfortunately some controls have structural problems with disable/enable. To reproduce this (on a click handler):

    disableForm() {
        this.formModel.forEach( (model: DynamicFormControlModel) => {
            model.disabled = true;
        });
        // does not help and should not be necessary
        // this.formService.detectChanges();
    }