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.

We've moved the forum!

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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

[SOLVED] Showing Yes instead of 1 in DOM with checkboxfield


Go to End


5 Posts   1281 Views

Avatar
LesC

Community Member, 70 Posts

18 November 2009 at 11:02pm

Edited: 19/11/2009 1:04am

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

Avatar
Carbon Crayon

Community Member, 598 Posts

19 November 2009 at 12:57am

Edited: 19/11/2009 12:57am

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'), 

Avatar
LesC

Community Member, 70 Posts

19 November 2009 at 1:03am

Hi Aram,

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

L

Avatar
UncleCheese

Forum Moderator, 4102 Posts

19 November 2009 at 3:16am

Thanks for stepping in, Aram!

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

Avatar
Carbon Crayon

Community Member, 598 Posts

19 November 2009 at 3:23am

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