udos86 / ng-dynamic-forms

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

Multiple relations not working #977

Open israelKusayev opened 5 years ago

israelKusayev commented 5 years ago

I'm submitting a


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

I'm using


NG Dynamic Forms Version: 7.2.0

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

Description

Multiple relation not working!! I want to apply multiple relations on select But every time he only refer to the first relation

"relation": [
                {
                    "action": "ENABLE",
                    "connective": "AND",
                    "when": [
                        {
                            "id": "WhereVTEWasDiagnosed",
                            "value": "ER"
                        },
                        {
                            "id": "DidThePatientHospitalized",
                            "value": "Yes"
                        }
                    ]
                },
                {
                    "action": "ENABLE",
                    "connective": "OR",
                    "when": [
                        {
                            "id": "WhereVTEWasDiagnosed",
                            "value": "During Hospitalization"
                        }
                    ]
                }
            ]

Am I doing something wrong??

Karamuto commented 5 years ago

Hello @israelKusayev ,

I am not 100% sure, but I think relations need to have different ids to work. You have used 'WhereVTEWasDiagnosed' 2 times, so only the first ist working.

@udos86 : shouldn't an error or warn message be printed to the console in this case?

stevehoper commented 5 years ago

@Karamuto @udos86 What is the syntax to use "when" in relations if "rootPath" is mapping to DynamicCheckboxGroupModel?

new DynamicCheckboxGroupModel({

            id: "bsCheckboxGroup",
            label: "Checkbox Group",
            group: [
                new DynamicCheckboxModel({

                    id: "checkboxGroup1",
                    label: "Checkbox 1",
                    value: true
                }),
                new DynamicCheckboxModel({

                    id: "checkboxGroup2",
                    label: "Checkbox 2",
                    value: true
                })
            ]
        }),

relations: [ { match: MATCH_DISABLED, when: [{rootPath: "bsCheckboxGroup.checkboxGroup1", value: true}] }, { match: MATCH_HIDDEN, when: [{rootPath: "bsCheckboxGroup.checkboxGroup2", value: true}] }, ],

Error msg: No related form control with id undefined could be found

Karamuto commented 5 years ago

Hello @israelKusayev,

this actually has nothing to do with the current thread. Could you open another one and paste a JSON of the resulting formGroup?