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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

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


Go to End


3 Posts   2556 Views

Avatar
Mrfixer

Community Member, 49 Posts

19 September 2011 at 9:06pm

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

Forum Moderator, 1391 Posts

20 September 2011 at 4:22am

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

Avatar
Mrfixer

Community Member, 49 Posts

21 September 2011 at 2:17am

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