5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2688 Views |
-
disabling/enabling fields based on dropdown selection

1 January 2009 at 12:12am
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
-
Re: disabling/enabling fields based on dropdown selection

1 January 2009 at 4:48am
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.
-
Re: disabling/enabling fields based on dropdown selection

1 January 2009 at 4:49am
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)...
-
Re: disabling/enabling fields based on dropdown selection

1 January 2009 at 8:04am Last edited: 1 January 2009 8:05am
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
-
Re: disabling/enabling fields based on dropdown selection

1 January 2009 at 8:57am
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.
-
Re: disabling/enabling fields based on dropdown selection

2 January 2009 at 1:13am
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
-
Re: disabling/enabling fields based on dropdown selection

3 May 2009 at 3:40am
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
| 2688 Views | ||
|
Page:
1
|
Go to Top |

