Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » [SOLVED] Showing Yes instead of 1 in DOM with checkboxfield

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: 846 Views
  • LesC
    Avatar
    Community Member
    70 Posts

    [SOLVED] Showing Yes instead of 1 in DOM with checkboxfield Link to this post

    Hi,

    I'd like to show the status of a checkbox field in the DOM list, but rather than it showing '1' I'd like to translate it to 'Yes', so it's easier for my clients to scan.

    I'm using this:

    $f->addFieldToTab("Root.Content.DirectoryEntries", new DataObjectManager(
    $this,
    'DirectoryEntries',
    'DirectoryEntry',
    array('DirectoryTitle' => 'Title','DirectoryPractitioner' => 'Practitioner', 'DirectoryCategoryTitle' => 'Category', 'Premium' => 'Premium'),
    'getCMSFields_forPopup'
    ));

    I'm guessing this is something simple?

    L

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: [SOLVED] Showing Yes instead of 1 in DOM with checkboxfield Link to this post

    Hi Les

    This is simple, just add this function to your dataobject (this example would be for the checkbox 'Premium':

       public function GetPremiumValue(){
          return ($this->Premium) ? 'Yes' : 'no';
       }

    Then change the array in the DOM definition to be:

    array('DirectoryTitle' => 'Title','DirectoryPractitioner' => 'Practitioner', 'DirectoryCategoryTitle' => 'Category', 'GetPremiumValue' => 'Premium'),

  • LesC
    Avatar
    Community Member
    70 Posts

    Re: [SOLVED] Showing Yes instead of 1 in DOM with checkboxfield Link to this post

    Hi Aram,

    That's exactly what I needed - thanks - I'm starting to understand how this all fits together now!!

    L

  • UncleCheese
    Avatar
    4085 Posts

    Re: [SOLVED] Showing Yes instead of 1 in DOM with checkboxfield Link to this post

    Thanks for stepping in, Aram!

    BTW, you don't need 'GetPremiumValue' in your array. You can just do PremiumValue, and name the function getPremiumValue().

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: [SOLVED] Showing Yes instead of 1 in DOM with checkboxfield Link to this post

    oh cool! I thought there was something like that but I could never remember what it was

    846 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.