7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Boolean Field
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1343 Views |
-
Boolean Field

26 April 2011 at 1:20pm
Hi, this question might have a really obvious answer, but I can't quite figure out how to do it! How would I go about getting a boolean field to display as 'Yes' or 'No' in the DOM list, as opposed to '1' or <blank>? I have it setup as a CheckboxField in my popup.
If anyone could point me in the right direction, I would be most appreciative!
-
Re: Boolean Field

26 April 2011 at 3:54pm
Hi Kyle,
I do it this way - on your dataobject class add a function to convert the value to Yes or No, then refer to the function instead of the DB field when defining the DOM or in your $summary_fields.
i.e.
class MyObject extends DataObject
{
static $db = array (
'Title' => 'Varchar(200)',
'Approved' => 'Boolean'
);static $summary_fields = array(
'Title' => 'Title',
'ApprovedNice' => 'Approved?'
);
//Generate Yes/No for DOM / Complex Table Field
public function ApprovedNice() {
return $this->Approved ? 'Yes' : 'No';
}
}Cheers
-
Re: Boolean Field

26 April 2011 at 6:07pm
That worked absolutely perfectly, thank you so much for the help!!!!
-
Re: Boolean Field

27 April 2011 at 10:38am
Doh! There's always an easier way in SilverStripe. Thanks for the tip Uncle Cheese. Still - can be useful in some situations, for instance I actually use that code to print out '***No*** Please review' to highlight records that need attention.
| 1343 Views | ||
|
Page:
1
|
Go to Top |


