21287 Posts in 5733 Topics by 2602 members
| Go to End | Next > | |
| Author | Topic: | 2492 Views |
-
TreeDropdownField: default value

15 May 2010 at 12:54pm
Hi,
does anybody know, how to get the saved value from a TrreDropdownField. How can you use "objectForKey"?
Can anybody give an example?new TreeDropdownField('BannerLinkInternID', 'Bitte eine interne Verlinkung wählen', 'SiteTree', 'ID', 'Title', true);
Greetings, Carsten.
-
Re: TreeDropdownField: default value

15 May 2010 at 10:33pm
does anybody know, how to get the saved value from a TrreDropdownField. How can you use "objectForKey"?
Can anybody give an example?Not exactly sure what you mean by objectForKey but what I think your getting at is how you get the BannerLinkIntern object. Well with a TreedropdownField you should have setup a has_one relation on that page of 'BannerLinkIntern' => 'SiteTree' so to access the object in templates you can use $BannerLinkIntern to access the related page or in the PHP $this->BannerLinkIntern() to get the object.
-
Re: TreeDropdownField: default value

16 May 2010 at 12:49am
Hi Willr,
thats all clear and works fine. But if i choose "home" from the list (for e.g.) and save the date to the db, then the page (backend) is reloaded and the value of the list is: "(Choose or type search)".
What do i have to do to show "Home" as the selected value after saving the data to DB?
Thanks for your reply, Carsten.
-
Re: TreeDropdownField: default value

16 May 2010 at 11:44am
Sounds like the 'home' value isn't saving. Have you got a has_one relationship setup correctly between this page and sitetree and ran a /dev/build. You should after building a correct has_one relationship a column in your database 'BannerLinkInternID' if you don't have this column then the treedropdownfield cannot save its value.
-
Re: TreeDropdownField: default value

30 May 2010 at 4:34am
I'm having the same problem, the field isn't saving back to the database. I can't get the link from my template and the field shows Choose a page rather than the page I selected.
The code I'm using is:
class Module extends Page {
static $db = array(
);
static $has_one = array(
'Photo' => 'Image',
'Header' => 'Image',
'LinkedPage' => 'SiteTree'
);
static $defaults = array(
"ShowInMenus" => 0,
);
static $can_be_root = false;
static $default_parent = 'HomePage';function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new ImageField('Header'));
$fields->addFieldToTab("Root.Content.Main", new ImageField('Photo'));
$fields->addFieldToTab('Root.Content.Main', new TreeDropdownField('LinkedPage', 'Page to link to', 'SiteTree'));
$fields->removeFieldFromTab('Root.Content.Main', 'MenuTitle');
$fields->removeByName('Metadata');
return $fields;
}}
and in the template
$LinkedPage.Link
Am I doing something wrong or is this a bug?
Cheers,
James Bench
-
Re: TreeDropdownField: default value

30 May 2010 at 11:25am
You need to use LinkedPageID instead of LinkedPage in your treedropdownfield constructor.
-
Re: TreeDropdownField: default value

9 July 2010 at 12:03pm
I'm a clouts, again I don't know what I'm doing wrong.
Same as above not getting id saved into the has_oneID field in the database.static $has_one = array(
"LinkTo" => "SiteTree"
);in getCMSFields_forPopup I'm adding and to and returning
$fields->addFieldToTab( 'Root.Main', new TreeDropdownField("LinkToID", "Link To This Page","SiteTree"));
I'm also trying SimpleTreeDropdownField as well, neither work.
Doing a little homepage captions dataobject, there's only about 3, easier enough to swap out manually. But I like using Silver Stripe to the EXTREME!
p.s. using SS 2.4
| 2492 Views | ||
| Go to Top | Next > |




