Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Change Checkbox Values to Yes, No From Boolean 1,0


Reply

3 Posts   1148 Views

Avatar
Mrfixer

19 September 2011 at 9:06pm Community Member, 49 Posts

I have Checkbox fields set up in DOM, they work cool, do what i want them to do, but what i realy need is for it to return to page in a more human readable format of Yes or No instead of Boolean 1 or 0, how can i do this?, i dont see any reference to how its done..

My Class file is:

class DogsForAdoptionClass extends DataObject
{
static $db = array (
'Title' => 'Text',
'Caption' => 'Text',
'Inocculated' => 'Boolean',
'Rabies' => 'Boolean',
'Spayed' => 'Boolean',
'Microchipped' => 'Boolean',
);

static $has_one = array (
'Attachment' => 'Image',
'DogsForAdoptionPage' => 'DogsForAdoptionPage'
);

public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Title'),
new TextareaField('Caption'),
new FileIFrameField('Attachment'),
new CheckboxField( 'Inocculated') ,
new CheckboxField( 'Rabies'),
new CheckboxField( 'Spayed'),
new CheckboxField( 'Microchipped'),
);
}
}

and Page type is:

public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->removeFieldFromTab('Root.Content.Main', 'MainPageContent');

$manager = new ImageDataObjectManager(
$this, // Controller
'Images', // Source name
'DogsForAdoptionClass', // Source class
'Attachment', // File name on DataObject
array(
'Title' => 'Title',
'Caption' => 'Caption',
'Inocculated' => 'Inocculated',
'Rabies' => 'Rabies',
'Spayed' => 'Spayed',
'Microchipped' => 'Microchipped'
), // Headings
'getCMSFields_forPopup' // Detail fields
// Filter clause
// Sort clause
// Join clause
);
$fields->addFieldToTab("Root.Content.Main",$manager);
return $fields;
}

Thanks in advance

Avatar
martimiz

20 September 2011 at 4:22am Forum Moderator, 1091 Posts

In your template, instead of using $Rabies, you can use $Rabies.Nice - this will return yes or no in your chosen language.

Avatar
Mrfixer

21 September 2011 at 2:17am Community Member, 49 Posts

Thanks Martimez,

Its really as simple as that?.. you just gotta love Silverstripe, many thanks, i decided to go with dropdowns in the main as the client decided to show, "Yes", "No" and "Unknown".

But im definatly taking onboard your help for the next time im needing checkbox values in a human readable format..

regards and thanks again