Item/Option Set Default values

When I set a config with “default” for inputs inside item sets or option sets (even if it has only one occurrence), It isn’t filled. Anyone knows why?

Seems to work fine inside an option set at least. See below for schema and result. Anything special about your schema? Can you post it here?

    <option-set name="radioOptionSet">
      <label>Single selection</label>
      <expanded>false</expanded>
      <help-text>Single selection radio option set</help-text>
      <occurrences minimum="1" maximum="1"/>
      <options minimum="1" maximum="1">
        <option name="option_1">
          <label>Option 1</label>
          <help-text>Help text for Option 1</help-text>
          <items>
            <input name="name" type="TextLine">
              <label>Name</label>
              <help-text>Text input</help-text>
              <occurrences minimum="1" maximum="1"/>
              <default>This is a default value 1</default>
            </input>
            <item-set name="minimum3">
              <label>Minimum 3</label>
              <occurrences minimum="3" maximum="0"/>
              <items>
                <input name="label" type="TextLine">
                  <label>Label</label>
                  <occurrences minimum="0" maximum="1"/>
                  <default>This is a default value 2</default>
                </input>
                <input name="value" type="TextLine">
                  <label>Value</label>
                  <occurrences minimum="0" maximum="1"/>
                  <default>This is a default value 3</default>
                </input>
              </items>
            </item-set>
          </items>
        </option>
        <option name="option_2">
          <label>Option 2</label>
          <help-text>Help text for Option 2</help-text>
        </option>
      </options>
    </option-set>

                <item-set name="nights">
                <label>Nights in location</label>
                <expanded>false</expanded>
                <occurrences minimum="1" maximum="1"/>
                <help-text>Information about how many days the tour will stay in this location.</help-text>
                <items>
                    <input name="minNights" type="Long">
                        <label>Stay Nights</label>
                        <occurrences minimum="1" maximum="1"/>
                        <default>1</default>
                    </input>
                    <option-set name="extraNights">
                        <label>Allow Extra Nights?</label>
                        <expanded>false</expanded>
                        <occurrences minimum="1" maximum="1"/>
                        <options minimum="1" maximum="1">
                            <option name="false">
                                <label>No</label>
                                <default>true</default>
                            </option>
                            <option name="true">
                                <label>Yes</label>
                                <items>
                                    <input name="maxNights" type="Long">
                                        <label>Maximum Nights</label>
                                        <occurrences minimum="1" maximum="1"/>
                                        <config>
                                            <default>5</default>
                                        </config>
                                    </input>
                                </items>
                            </option>
                        </options>
                    </option-set>
                </items>
                </item-set>

Two problems here.
First of all, this scheme won’t even validate because <expanded> is not allowed inside <item-set>, only inside <option-set>.
Secondly, <default> for the last input should not be inside <config>.

Here’s the correct schema:

<item-set name="nights">
      <label>Nights in location</label>
      <occurrences minimum="1" maximum="1"/>
      <help-text>Information about how many days the tour will stay in this location.</help-text>
      <items>
        <input name="minNights" type="Long">
          <label>Stay Nights</label>
          <occurrences minimum="1" maximum="1"/>
          <default>1</default>
        </input>
        <option-set name="extraNights">
          <label>Allow Extra Nights?</label>
          <expanded>false</expanded>
          <occurrences minimum="1" maximum="1"/>
          <options minimum="1" maximum="1">
            <option name="false">
              <label>No</label>
              <default>true</default>
            </option>
            <option name="true">
              <label>Yes</label>
              <items>
                <input name="maxNights" type="Long">
                  <label>Maximum Nights</label>
                  <occurrences minimum="1" maximum="1"/>
                  <default>5</default>
                </input>
              </items>
            </option>
          </options>
        </option-set>
      </items>
    </item-set>
1 Like

<expanded> was not affecting the form validation, Since it is working now. But as you can see in, here I have <default>1</default> and it didn’t worked too, that’s why I put inside the config tag.

Until I have removed expanded, I wasn’t even able to use the content type. Once I removed it, the content type showed up with default values working in all fields:

Hmm I’ve placed this part of code inside a mixin and I’m using it as x-data, because it’s a very large content type and the navigation system on the top menu helps a lot on editing the things I want. So, That may be the reason?

So what you are saying is that default values don’t work for an item-set inside a mixin, but outside of the mixin they do (with the same schema)? I’ll have to test this one, that might actually be the reason.

Btw, which version of XP are you on?

6.10.3. I’ll try to update today to latest one and check if it works.
Edit:
Just updated to 6.11.1 and it don’t worked too. I’ve tested the code placing it in the content-type <form> and also including the mixin with <inline mixin="mixin-name" /> both worked. Just when it’s an x-data mixin it don’t set the default values.

1 Like

Yep, you’re right. Default values are not working inside x-data mixin and that’s a bug. We registered it, so you can follow up the progress: https://github.com/enonic/xp/issues/5624.

The bugfix will be a part of 6.12 release later this month.

2 Likes