5095 Posts in 1518 Topics by 1114 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 429 Views |
-
Visual select field

18 July 2011 at 1:27pm
Does anyone know of a way to achieve a radio group like in the attached image?
I don't think it's built in to SS but I was hoping someone might have done something like it before. I want my CMS users to be able to choose from a few different layout options within the one page type with a visual cue to what each one looks like.
Thanks
-
Re: Visual select field

18 July 2011 at 2:18pm Last edited: 18 July 2011 2:22pm
So much easier than I imagined!
$ArrayMap = array(
'1' => '<img src="/ImgDirectory/ImageName.jpg" alt="" width="60" height = "60" /> Title 1',
'2' => '<img src="/ImgDirectory/ImageName2.jpg" alt="" width="60" height = "60" /> Title 2'
);
$fields->addFieldToTab("Root.Content.Main", new OptionSetField('FieldName', 'Field Name', $ArrayMap));Other way - creating field dynamically from data objects:
$ArrayMap = DataObject::get('DataObjectClassName')->map("ID", "Thumb");
$fields->addFieldToTab("Root.Content.Main", new OptionSetField('FieldName', 'Field Name', $ArrayMap));On the relevant data object class
static $has_one = array (
'Image' => 'Image'
);public function getThumb() {
return $this->Image()->CroppedImage(60,60)->Tag;
}Probably needs some cleaning up so it doesn't crash if there's no image attached but concept works.
| 429 Views | ||
|
Page:
1
|
Go to Top |

