1779 Posts in 582 Topics by 556 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 183 Views |
-
Custom title on CheckboxSetField

26 October 2012 at 11:08pm
Hi!
Is there a way to set an custom title on the CheckboxSetField items in SS3? eg. I have a Product with an title and a group title and I would like to display both titles in the CheckboxSetField, like "[x] Product title, (Group Title)".
class Deal extends DataObject {
public static $db = array(
'Title' => 'Varchar(255)'
);public static $has_one = array(
"HomePage" => "HomePage"
);public static $many_many = array(
"Products" => "Product"
);public function getCMSFields()
{
return new FieldList(
new TextField("Title", _t("Deal.Title", "Tittel")),
new CheckboxSetField('Products', _t("Deal.MaltProduct", "Produkter"), DataObject::get('Product'))
);
}
} -
Re: Custom title on CheckboxSetField

2 November 2012 at 11:55am
The CheckboxSet api simply takes an associative array which can be used with the SS_Map class to generate an array from the DataList.
public function getCMSFields() {
$products = new SS_Map(Product::get(), 'ID', 'DropdownTitle');return new FieldList(
new TextField("Title", _t("Deal.Title", "Tittel")),
new CheckboxSetField('Products', _t("Deal.MaltProduct", "Produkter"), $products->toArray())
);
}Then define a getDropdownTitle() function on your Product object to return the format you want.
You could also manually create the associative array inside this function (using a foreach loop) but that's a little messier.
| 183 Views | ||
|
Page:
1
|
Go to Top |


