Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

OptionFieldSet not saved in Setting tab


Go to End


2 Posts   1114 Views

Avatar
namnn96

Community Member, 4 Posts

3 February 2016 at 2:13pm

Hi guys,

I am setting an optionsetfield in page's setting tab. As I save click save and publish it brings me back to the default option

$fields->addFieldsToTab('Root.Settings', array(
$options = OptionsetField::create('DisplayBanner', 'Display banner', array(
'1' => "Parent",
'2' => "Custom",
'3' => "Global"
), '1'),
DisplayLogicWrapper::create(
$banner = UploadField::create('Banner')
)->displayIf('DisplayBanner')->isEqualTo('2')->end()

));

It is not saving my option, thanks in advance

Avatar
Kirk

Community Member, 67 Posts

4 February 2016 at 4:37pm

Try removing the 4th parameter from the OptionSet Field as that is setting the value to 1 every time.
OptionSet Field inherits the constructor form DropdownField which uses the 4th parameter as the value

    /**
     * @param string $name The field name
     * @param string $title The field title
     * @param array $source An map of the dropdown items
     * @param string $value The current value
     * @param Form $form The parent form
     * @param string|bool $emptyString Add an empty selection on to of the {@link $source}-Array (can also be
     *                  boolean, which  results in an empty string).  Argument is deprecated
     *                  in 3.1, please use{@link setEmptyString()} and/or
     *                  {@link setHasEmptyDefault(true)} instead.
     */