I'm running AEM Forms 6.3 and experience an issue when dynamically populating a dropdown.
On initialize of a certain field I add an array of items to the dropdown using DropDown.items = array. Now when the filed changes I'd like to replace the items with another set of items. That doesn't work. The new items are appended so the drop down list get's longer. What's strange is that the newly created set of items can be changed but the original assignment is always kept.
Further more printing DropDown.items to the console the correct items show up.
To further illustrate that
# initial assignment - 5 items - DropDown list contains 5 items visually - DropDown.items.length = 5
# new assignment - 3 items - DropDown list contains 8 items visually - DropDown.items.length = 3
Verified in Chrome and Firefox.
We are running AEM Forms JEE - SP1 - available patches are installed.
James_R_Green
James_R_Green
12-02-2018
I can reproduce this when a dropdown list is bound.
The error doesn't occur when the dropdown is unbound.
Tested this on 6.2 and it doesn't append the values (which is what I would expect), to me the functionality has changed between 6.2 and 6.3 and I don't know why you would want it to work the way it appears to work in 6.3 so I personally think this is a bug.
A few options:
* if two dropdowns (dropdownA and dropdownB) are bound to the same field, and you set dropdownB.items = ["A=A","B=B","C=C"]; - dropdownB exhibits the appending you have reported *but* dropdownA does not. You could use this to your advantage and hide dropdownB - not pretty, but if you are desperate for a workaround it might help. It will also depend how many dropdowns you have on your form whether this is a viable option.
* Or similarly use an unbound field on the form and copy the value to a bound copy of the field on submit.
* Otherwise, try creating a custom widget for dropdownlist and see if that has the same issue.
smacdonald2008
smacdonald2008
12-02-2018
Glad james was helpful. This is the point of the AEM community. To try and help as much as possible.
Maruan_Sahyoun
Maruan_Sahyoun
12-02-2018
Hi James,
thanks for taking the effort and also providing a workaround solution. What we ended up with is to remove the binding on the field and pass the selected information in another field.
Moving forward we'll go with schema binding anyway.
Many thanks also to Scott and Jagjeet for looking into that.
With kind regards
Maruan
Maruan_Sahyoun
Maruan_Sahyoun
07-02-2018
So what you are saying is that the scripting should go to the XFA Template?
Btw. it did work in AEM Forms 6.2.
jagjeetthukral
jagjeetthukral
07-02-2018
I don't think this is a bug.
There is a point we are missing here, since that field is mapped to an XFA element, it is supposed to have values that only XFA dropdown is mapped to.
The right approach to handle your scenario should be to have the dropdown dynamic in XFA itself. The process remain almost similar to what you are doing in Adaptive Forms
Hope this helps !!!
Cheers,
Jagjeet Singh
Maruan_Sahyoun
Maruan_Sahyoun
07-02-2018
Btw. this is a very simple Options Expression I used for testing. Other events show the same behaviour.
if (Anwendungsfall.value == 1) {
this.items = ["A=A", "B=B", "C=C", "D=D", "E=E"];
} else {
this.items = ["A=A", "B=B", "C=C", "D=D", "E=E"];
}
smacdonald2008
smacdonald2008
07-02-2018
That is interesting. Question is if there is a bug or is there something that is missed when setting up the XFA model. I have asked the AEM Form team to look here.
Maruan_Sahyoun
Maruan_Sahyoun
07-02-2018
This happens only for an XFA template based adaptive form. The DropDown list is bound to the XFA based data model. Creating an adaptive form from scratch doesn't show that behavior.
smacdonald2008
smacdonald2008
07-02-2018
Are you following an online doc for this - can you point the community to that to see if that can be reproduced.