Jump to:

5539 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » disabling/enabling fields based on dropdown selection

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

Page: 1
Go to End
Author Topic: 3238 Views
  • Aram
    Avatar
    Community Member
    598 Posts

    disabling/enabling fields based on dropdown selection Link to this post

    Hi guys

    I am trying to grey out some fields in the CMS based on the selection of a dropdown above. So I have a drop down with home/away as options and then I have an away club address underneath which I want to be greyed out and uneditable if home is selected.

    Any ideas?

    cheers

    aram

  • UncleCheese
    Avatar
    4085 Posts

    Re: disabling/enabling fields based on dropdown selection Link to this post

    Hi, aram,

    You need to use the Behaviour class to add a javascript behavior to your select box. See the file I posted here http://www.silverstripe.org/customising-the-cms/show/251409. I did this sort of thing in the VerticalTabSet class. The only difference is yours will use an onchange event, but for the most part, you should be able to copy a lot of that code.

    Let me know if you have any questions.

  • UncleCheese
    Avatar
    4085 Posts

    Re: disabling/enabling fields based on dropdown selection Link to this post

    Also, if you're interested in using radio buttons instead, the SelectionGroup field is really easy to use. (the behaviour you see in a FileIFrame field, for instance)...

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: disabling/enabling fields based on dropdown selection Link to this post

    thanks for the help

    I tried to get the Java stuff working but failed miserably, which isn't so surprising as i have yet to properly learn any javascript!

    I think SelectionGroup souds like a great solution for me right now so I will leave the dropdown untill I have time to learn a bit of js.

    I cant seem to find any documentation on the SelectionGroup and the API doc isnt incredibly clear on implementation, any chance you could post an example?

    Once again, thanks

    Oh and Happy new year! I think 2009 will be a good year for SS

  • UncleCheese
    Avatar
    4085 Posts

    Re: disabling/enabling fields based on dropdown selection Link to this post

    I use it in ImageGalleryAlbum.php, if you have that handy.

    $f->push(new SelectionGroup("Source", array(
       "new//Create a new folder" => new HiddenField(""),
       "existing//Use an existing folder" => new FieldGroup("",
          new DropdownField("FolderID","",DataObject::get("Folder",null,"Title ASC")->toDropdownMap('ID','Filename'))
       )
    ))
    );

    where the text before the // is the value of the radio button and after it is the label. Notice i use an empty hiddenfield, since in this case, clicking "use an existing folder" exposes nothing.

    Also, if you plan to use this in a popup, you'll need to use the PopupSelectionGroup that i created for the image gallery.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: disabling/enabling fields based on dropdown selection Link to this post

    mate your a legend that works perfectly!

    I love adding details like that to the interface it really seems to add an extra level usability.

    anyway thanks so much for your help

  • Nexus Rex
    Avatar
    Community Member
    8 Posts

    Re: disabling/enabling fields based on dropdown selection Link to this post

    aram - Do you mind posting the full code for your form that you used to disable/enable fields based upon another fields selection value. I need to get this done, but would appreciate a more simple step-by-step explanation.

    A link to see the live example would be great as well.

    Thank you,

    Travis Cable

    3238 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.