Default value in optional item-set


#1

Enonic version: 7.2.3
OS: Mac

Throughout our site we use several optional item sets in our parts and layouts, i.e. item sets with <occurrences minimum="0" maximum="1"/>. Some input fields (RadioButtons and ComboBoxes) inside <items>have default values, which I expect to be used when adding one (or more) occurence(s) of the items. In Enonic XP 6.15 this is also what I have experienced, but upgrading to Enonic XP 7.2, the default values suddenly seems to cause an instance of the items to be generated automatically.

This sample layout illustrates the issue:

<layout>
  <display-name>Test layout</display-name>
  <form>
    <item-set name="myItems">
      <label>Item</label>
      <items>
        <input name="value" type="RadioButton">
          <label>Value</label>
          <occurrences minimum="1" maximum="1"/>
          <config>
            <option value="1">One</option>
            <option value="2">Two</option>
            <option value="3">Three</option>
          </config>
          <default>1</default>
        </input>
      </items>
      <occurrences minimum="0" maximum="1"/>
    </item-set>
  </form>
  <regions>
    <region name="main"/>
  </regions>
</layout>

I would expect the form in content studio to look like this when first adding the layout to a page:

image
(this is also how it would look in 6.15)

But in XP 7 it looks like this:

image

As you can see, the item is added automatically (I never get the button), even though it should be optional to add it. Removing the default value of the radio button fixes the problem, but then I won’t have a default value for the radio button when the editor actually choses to add an item.

In our production code we have much more complex item sets, and removing all default values is not an option. Neither is requiring editors to X-out (close) autogenerated items when not needed. Currently this issue stops us from going in production with XP 7.


#2

Thank you for reporting this. This is definitely an interesting issue. The problem here is that an input will always get a default value (if it’s set), even if the input is optional. In this case the item-set will also be automatically added/expanded since it’s not empty.

We have created an issue for that which we will discuss on our next roadmap meeting to decide what should be the behaviour in this case.

Will keep you updated.


#3

Hello again. We have labeled this as a bug. Item-set will not be auto-expanded if it’s optional, even if one of its inputs has a default value. Will be fixed in one of the future patch releases.


#4