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.

General Questions

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

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

Update field on state change of another field


Reply

4 Posts   399 Views

Avatar
dylangrech92

12 October 2013 at 2:30am Community Member, 17 Posts

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

14 October 2013 at 6:03pm Community Member, 528 Posts

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

14 October 2013 at 7:08pm (Last edited: 14 October 2013 7:08pm), Community Member, 83 Posts

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

14 October 2013 at 10:06pm Community Member, 17 Posts

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