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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

showing Boolean Value as YES or NO in Complex Table Field


Reply


7 Posts   1798 Views

Avatar
Nicolaas

Forum Moderator, 213 Posts

6 January 2011 at 6:36pm

Hi

Stupid question - what is the easiest way to show a Boolean Value as YES / NO rather than 1 or 0 in a Complex Table Field????

Thank you

Nicolaas

Avatar
swaiba

Forum Moderator, 1799 Posts

7 January 2011 at 1:17pm

I'd use casting... like this...

class MyObject extends DataObject
{
static $db = array(
'MyBool' => 'Boolean',
);
public static $summary_fields = array (
'MyBoolText' => 'YesNo'
);
static $casting = array(
'MyBoolText' => 'Text',
);
public function MyBoolText(){
return $this->MyBool ? 'Yes' : 'No';
}
}

Avatar
BenWu

Community Member, 90 Posts

15 June 2012 at 9:59pm

works. many thanks

Avatar
Nobrainer Web

Community Member, 137 Posts

22 June 2012 at 9:39am

I think it's possible to use $SomeField.Nice

Avatar
Nicolaas

Forum Moderator, 213 Posts

22 June 2012 at 9:06pm

Edited: 22/06/2012 9:07pm

Yes, you are probably right.

I think you need to use this:

table = ComplexTableField....

      $table->setFieldCasting(array(
         'MyBooleanField' => 'Boolean->Nice',
         'Total' => 'Currency->Nice'
      ));

Avatar
Nicolaas

Forum Moderator, 213 Posts

22 June 2012 at 9:13pm

ok, so the question then is, how can we set these formatting rules for the summary_fields....

Avatar
copernican

Community Member, 189 Posts

23 June 2012 at 7:55am

I think this will work...

static $db = array(
'myBool' => 'Boolean'
);

static $summary_fields = array(
'myBool'
);

public function myBool(){
return ($this->myBool==true ? 'Yes':'No');
}

It should then show Yes/No instead of 1/0.