Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Change Checkbox Values to Yes, No From Boolean 1,0

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1093 Views
  • Mrfixer
    Avatar
    Community Member
    49 Posts

    Change Checkbox Values to Yes, No From Boolean 1,0 Link to this post

    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

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Change Checkbox Values to Yes, No From Boolean 1,0 Link to this post

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

  • Mrfixer
    Avatar
    Community Member
    49 Posts

    Re: Change Checkbox Values to Yes, No From Boolean 1,0 Link to this post

    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

    1093 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.