Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » HasOneComplexTableField and Booleans

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

Page: 1
Go to End
Author Topic: 1403 Views
  • _Vince
    Avatar
    Community Member
    161 Posts

    HasOneComplexTableField and Booleans Link to this post

    I have a HasOneComplexTableField on a page in the CMS and one of the columns displayed is of type 'Boolean'.

    It's saved in the database as either 1 or 0 and it's DISPLAYED as either 1 or 0. Which is fair enough but potentially confusing for the end users.

    Is there some way that I can "decode" the 1 and 0 into something like 'Y' and 'N' or whatever?

    I only want that for the display.

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: HasOneComplexTableField and Booleans Link to this post

    Perhaps create a new function (or try overloading your db field in your object). So say your boolean is "HasValue" => "Boolean" you can define something like getHasValueNice() { return ($this->HasValue) ? "Yes" : "No"; } and change your TableField to use HasValueNice rather then HasValue.

    You could try overload it by creating a getHasValue() function (same as the dbfield) but not sure if you will run into other issues

  • _Vince
    Avatar
    Community Member
    161 Posts

    Re: HasOneComplexTableField and Booleans Link to this post

    Hey, that sounds interesting. I'll give it a go.

    I can just see the end user asking what all those ones and zeros mean and I might as well preempt them.

    ADDED:

    Yup! Works perfectly. Sweet! Thanks!

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