udos86 / ng-dynamic-forms

Rapid form development library for Angular
ISC License
1.32k stars 369 forks source link

DynamicFormControlCondition - improvement on DynamicFormRelationService matchesCondition #1182

Open Wchua opened 10 months ago

Wchua commented 10 months ago

I'm submitting a


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

I'm using


NG Dynamic Forms Version: `18.0.0`

[ ] Basic UI
[ ] Bootstrap UI  
[ ] Foundation UI
[ ] Ionic UI
[ ] Material  
[ ] NG Bootstrap
[X ] Prime NG

Description

Use case

I want to show/hide some fields based on the value of other fields (selectModel) which has custom object as options/values.

Problem

The DynamicFormRelationService does the relations match on the matchesCondition function using strict equality which when comparing objects returns false.

Proposed Solution

Add an optional function called matched to the DynamicFormControlCondition which, in case it is defined, it will take precedence over the current value property.

export interface DynamicFormControlCondition {
    id?: string;
    rootPath?: string;
    status?: string;
    value?: any;
    matched?: (relatedFormControlValue: any) => boolean; // Has precedence over value
}

This way we can match the value correctly.