[MGNLUI-2683] SwitchableField saving behaves erratically Created: 14/Feb/14  Updated: 05/Mar/14  Resolved: 04/Mar/14

Status: Closed
Project: Magnolia UI
Component/s: forms
Affects Version/s: 5.2.2
Fix Version/s: 5.2.3

Type: Bug Priority: Critical
Reporter: Ondrej Chytil Assignee: Mikaël Geljić
Resolution: Fixed Votes: 0
Labels: maintenance
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: XML File config.modules.rssaggregator.apps.rssAggregator.subApps.detail.editor.form.tabs.scheduleTab.xml    
Issue Links:
Relates
relates to MGNLUI-2712 info.magnolia.ui.form.field.definitio... Closed
causality
is causing MGNLUI-2730 ClassCastException in SelectFieldFact... Closed
relation
is related to MGNLRSSAGG-143 Enable separate scheduling for feeds Closed
Template:
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:

 Description   

When saving a SwitchableField called 'switch', with its default transformer:

  • Default selection is ignored (expected to save at least the 'switch' property to the name of the default selected option).
  • Default value of the default selection is ignored (expected to save e.g. switchtext = myDefaultTextValue)
  • Only when entering changes in one of the fields will then save all properties at once.

Hint: We mostly need to trigger transformer to write to the item on switchable selection changes (see selectionListener).

As a side note:

  • There should be no preselection when using radio buttons, unless explicitly configured (option selected=true)
  • For select dropdowns, in case there is no default preselection, field should behave like a native select, i.e. never be blank and show first option.
  • Finally, we should save switchable field's subfields 'on demand' (currently it's just all at once).

------ Original description ------

Using info.magnolia.ui.form.field.definition.SwitchableFieldDefinition with hidden fields (see attached configuration) results in two bugs:

  • original switch is not reflecting its default value which is not saved
  • even when switch is set to reveal hidden fields their default values are ignored as well on save

Steps to reproduce using attached config:

  • Open the dialog and save without any other action
    • default value of the SwitchableFieldDefinition should be saved but it's not
    • default values of hidden properties should be saved as well (in this case may be intention to not save them)
  • Open the dialog, set the SwitchableFieldDefinition to true (which will result in revealing two other fields), then save
    • default value of SwitchableFieldDefinition is saved properly this time
    • however underlying properties are still ignored until modified


 Comments   
Comment by Mikaël Geljić [ 21/Feb/14 ]

First, to avoid confusion and narrow down the issue, in the provided config:

  • HiddenFieldDefinition has no 'defaultValue' so no property can be expected to be saved when 'hidden' is selected
  • 'transformerClass' is explicitly set to some MailSecurityTransformer; I guess you should use the SwitchableTransformer (which is the default for SwitchableFieldDefinition, i.e. if no transformerClass is configured)
  • I used the 'cron' TextFieldDefinition directly instead of the composite field; then when I enter 'some text' I do get BOTH switchable=cron and switchablecron='some text' properties, I also get switchablehidden='someDefaultValue' as a matter of fact.

So to me the actual issue here is down to one thing:

  • When saving form and not setting switchable field value explicitly, no switchable nor switchablehidden property with default value is set.
Comment by Roman Kovařík [ 03/Mar/14 ]

Reopened

  1. ^ You changed the goal of this ticket in the above comment. Could you also correct the description of this issue to be clear what was fixed in the end? (cross out no-need-to-fix points in the description).
  2. SelectFieldFactoryTest Could you get rid of underscores in the test names?
  3. When using SelectFieldDefinition with defaultValue: defaultValue is not respected because info.magnolia.ui.form.field.factory.SelectFieldFactory.createDefaultValue(Property<?>) takes first value from iterator. Is this desired behavior?
Comment by Mikaël Geljić [ 04/Mar/14 ]

1. Updated. By the way the default selection behaviors are the input/select defaults, and are the same as in 4.5.
2. Done.
3. Yes, defaultValue is anyway ignored for any kind of select, there we rely at most on having an option configured with 'selected=true' (old-fashioned but nothing new here).
Now as I detailed in the description, what that means for select dropdowns is that if there's no option configured as 'selected', then first option will be selected (now even if options are sorted alphabetically FWIW); for radio selection on the other hand, we make no pre-assumption and leave all options unselected.

Generated at Mon Feb 12 08:59:07 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.