Jump to:

10993 Posts in 2727 Topics by 1818 members

All other Modules

SilverStripe Forums » All other Modules » Radiobuttons with images instead of Text (OptionsetField)

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1542 Views
  • Andre
    Avatar
    Community Member
    126 Posts

    Radiobuttons with images instead of Text (OptionsetField) Link to this post

    Hi, I'm planning to build an eCard Module. Therefore I need a Form with Radiobuttons in the Frontend like it's used in the Poll Tutorial (Tut 3). But instead of simple Text next to the single Radiobuttons I want a small preview of the Cards to select one. How is it possible to fill an OptionsetField with more than just Text? Is it possible to fill the Array with ImageObjects?

  • Andre
    Avatar
    Community Member
    126 Posts

    Re: Radiobuttons with images instead of Text (OptionsetField) Link to this post

    Is this impossible with the given Objects or does noone have an Idea?

  • Funfair77
    Avatar
    Community Member
    49 Posts

    Re: Radiobuttons with images instead of Text (OptionsetField) Link to this post

    Is your problem solved? Did you make the eCard Module?
    I'm looking for an e-card module for SS.

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Radiobuttons with images instead of Text (OptionsetField) Link to this post

    Well... I have just made a really nice HACK for this, but I also have an idea how to make this nicely...

    sapphire\forms\OptionsetField.php

    function Field() {
    ...
    if ($this->name == 'NAMEOFFORMFIELD') {
    $options .= "<li class=\"".$extraClass."\">"
    ."<input id=\"$itemID\" name=\"$this->name\" type=\"radio\" value=\"$key\"$checked $disabled class=\"radio\" />"

    //image added here...
    ."<img src=\"cms/images/check.png\" />"

    ."<label for=\"$itemID\">$value"
    ."</label>"
    ."</li>\n";
    }
    else {
    $options .= "<li class=\"".$extraClass."\"><input id=\"$itemID\" name=\"$this->name\" type=\"radio\" value=\"$key\"$checked $disabled class=\"radio\" /> <label for=\"$itemID\">$value</label></li>\n";
    }
    ...
    }

    so that is the hack, so the nice way to do this is to create an ImageOptionsetField, that inherits from OptionsetField and then allows setting of an array to handle the images. For the project this is in - I'm going to recommend this, but since I'm not coding it myself, I haven't added it here...

    enjoy!

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