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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Update field on state change of another field


Go to End


4 Posts   1851 Views

Avatar
dylangrech92

Community Member, 17 Posts

12 October 2013 at 2:30am

I have two drop down fields in the admin and I want one's values to change corresponding to the selection in the other one. What can I do? I would like to avoid AJAX calls.

Here is some sample code so that you can have a basic idea:
$menus = DataObject::get( 'BassMenu' );
if( $menus ) {
$fields->addFieldToTab( 'Root.Content.Main',
new DropdownField( 'BrowseMenuID', 'Select Browse Menu',
$menus->toDropDownMap( 'ID', 'Name' ), '', null, '' ),
'Content' );
}

$subMenuCategories = DataObject::get( 'BassMenuItem', 'ParentMenuID = '.$this->BrowseMenu()->ID );
$fields->addFieldToTab( 'Root.Content.Main',
new DropdownField( 'SubMenuID', 'Select under which sub-menu this page and sub-pages should show',
$subMenuCategories->toDropDownMap( 'ID', 'Title' )
) );

Avatar
zenmonkey

Community Member, 545 Posts

14 October 2013 at 6:03pm

Realisitcally if you want to avoid AJAX cales you'll have to wait for the user to save the object to trigger a refresh. The only other option is to use a GroupedDropdownField that you populate with all BassMenuItems grouped by BassMenu and use some javascript to hide ones that match the the one selected in the first dropdown

I think there is a module that does populate dropdowns based on other fields, but I can't find it

Avatar
lx

Community Member, 83 Posts

14 October 2013 at 7:08pm

Edited: 14/10/2013 7:08pm

Maybe you can use this module.
http://www.leftandmain.com/silverstripe-screencasts/2013/01/28/display-logic-module-for-silverstripe-3/

I have never tried it myself , so i am not 100% sure if it is what you are looking for.

Avatar
dylangrech92

Community Member, 17 Posts

14 October 2013 at 10:06pm

Thanks for the responses guys, Sorry for the late reply was out for the weekend.

lx I cannot use that module because we're not allowed to at work :/ and we use ss 2.4

So my only option is to use ajax :/ Well was kinda expected but thanks for the info