Jump to:

22997 Posts in 11853 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Update field on state change of another field

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

Page: 1
Go to End
Author Topic: 273 Views
  • dylangrech92
    Avatar
    Community Member
    16 Posts

    Update field on state change of another field Link to this post

    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' )
          ) );

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: Update field on state change of another field Link to this post

    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

  • lx
    Avatar
    Community Member
    81 Posts

    Re: Update field on state change of another field Link to this post

    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.

  • dylangrech92
    Avatar
    Community Member
    16 Posts

    Re: Update field on state change of another field Link to this post

    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

    273 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.