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
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
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
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';
}
}
works. many thanks
I think it's possible to use $SomeField.Nice
Yes, you are probably right.
I think you need to use this:
table = ComplexTableField....
$table->setFieldCasting(array(
'MyBooleanField' => 'Boolean->Nice',
'Total' => 'Currency->Nice'
));
ok, so the question then is, how can we set these formatting rules for the summary_fields....
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.
Nice() will work on summary fields as well.
private static $db = array(
'myBool' => 'Boolean'
);
private static $summary_fields = array(
'myBool.Nice' => 'My boolean value'
);