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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

SimpleTreeDropdownField value not saved


Go to End


3 Posts   1483 Views

Avatar
k0m0r

Community Member, 39 Posts

8 April 2010 at 3:46am

Hi there.
I encountered a following problem with SimpleTreeDropdownField.
I have a following structure:

1. FaqList page with collection of FaqItem data objects (managed by DOM).
2. Each FaqItem may contain many RelatedItem data objects (managed by DOM in pop-up - this works fine).
3. Each RelatedItem pop-up has a SimpleTreeDropdownField.

Now, when I create a new FaqItem, save it, and then add a RelatedItem, everything works fine.
I can save and display (in CMS and online) all the values except for the 'LinkToRelated' field.
The SimpleTreeDropdownField value simply isn't saved.
Even in CMS, after saving the RelatedItem popup - I can see that the select value goes back to the empty line ('select a page').

Any idea what's wrong?

Here is a piece of code:

class FaqList extends Page {

public static $db = array(
);

public static $has_many = array(
"Items" => "FaqItem",
);

function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new DataObjectManager(
$this,
'Items',
'FaqItem',
array('Title' => 'Title'),
'getCMSFields_forPopup'
);
$fields->addFieldToTab('Root.Content.Items',$manager);
return $fields;
}
}

class FaqItem extends DataObject {

public static $db = array(
);

public static $has_one = array(
"FaqList" => "FaqList",
);

public static $has_many = array(
"RelatedItems" => "RelatedItem",
);

function getCMSFields_forPopup() {
$fields = new FieldSet();
$manager = new DataObjectManager(
$this,
'RelatedItems',
'RelatedItem',
array('Title' => 'Title'),
'getCMSFields_forPopup'
);
$fields->push($manager);
return $fields;
}
}

class RelatedItem extends DataObject {

public static $db = array(
);

public static $has_one = array(
"ItemParent" => "DataObject",
"LinkToRelated" => "SiteTree",
);

function getCMSFields_forPopup() {
$fields = new FieldSet();
$dropdown = new SimpleTreeDropdownField('LinkToRelated','Link to page','SiteTree');
$dropdown->setEmptyString('-- Select a page --');
$fields->push($dropdown);
return $fields;
}
}

Avatar
UncleCheese

Forum Moderator, 4102 Posts

8 April 2010 at 3:56pm

$dropdown = new SimpleTreeDropdownField('LinkToRelatedID','Link to page','SiteTree');

Avatar
k0m0r

Community Member, 39 Posts

8 April 2010 at 6:42pm

Thank You very much, I knew I overlooked something :)