[MGNLUI-4023] SelectField options don't allow to set the same value into two different select options. Created: 22/Sep/16  Updated: 08/Mar/21  Resolved: 08/Mar/21

Status: Closed
Project: Magnolia UI
Component/s: forms
Affects Version/s: 6.2
Fix Version/s: None

Type: Bug Priority: Low
Reporter: Christian Ringele Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File SelectFieldFactory.patch     PNG File combo-with-dupe-options.png    
Issue Links:
causality
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:
Epic Link: Dialog UX improvements

 Description   

If you set into two select field options the same value, the dialog does not open.

I admit its a rare case, but its still a bug and I can imagine use cases where this is needed.

The reason for the error is in:
SelectFieldFactory line 149 that is uses the options value as being the item ID in the data container optionContainer:

Object value = DefaultPropertyUtil.createTypedValue(fieldType, option.getValue());
Item item = optionContainer.addItem(value);

I created a patch, I think the SelectOptionDefinition name is the better value, as its for sure unique:
SelectFieldFactory.patch

I delegated to a method info.magnolia.ui.form.field.factory.SelectFieldFactory.determinateBestItemName(SelectFieldOptionDefinition) to determine the best name, in some cases the name is null. Maybe a better determination can be found for production code.



 Comments   
Comment by Christian Ringele [ 26/Sep/16 ]

Its clear that the case having in top selectOption the same value is rare and doesn't make much sense.

One of the resulting problems is:
In the end storing same value by two fields will also lead to confusion on resolving the value to the chosen dropdown:
If second option was chose with the same vale, on re-opening the system will most likely choose the first one found.
The system can not now which one of the two options was chose which store the same value.

BUT it still should not result in an error which prevents the dialog from opening.

Comment by Roman Kovařík [ 08/Mar/21 ]

rgange Could you check if this happens in the new framework?

Comment by Richard Gange [ 08/Mar/21 ]

Looking at the detail for optionListDatasource its options are of List type which should allow duplicates. Then looking at the detail for ComboBoxFieldFactory I don't see anywhere the options are being used. So it is decoupled.

And testing it does seem to be working:

Generated at Mon Feb 12 09:12:29 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.