Jump to:

7938 Posts in 1541 Topics by 945 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Boolean Field

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: 1783 Views
  • kylehudson00
    Avatar
    Community Member
    22 Posts

    Boolean Field Link to this post

    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!

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: Boolean Field Link to this post

    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

  • kylehudson00
    Avatar
    Community Member
    22 Posts

    Re: Boolean Field Link to this post

    That worked absolutely perfectly, thank you so much for the help!!!!

  • UncleCheese
    Avatar
    4085 Posts

    Re: Boolean Field Link to this post

    FYI, this is built in. You just do $YourField.Nice.

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: Boolean Field Link to this post

    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.

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