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.

Customising the CMS /

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

Checkbox in CMS


Go to End


4 Posts   1251 Views

Avatar
Robke

Community Member, 4 Posts

16 July 2013 at 12:54am

Edited: 16/07/2013 12:55am

hello,

this is my first post in SS forums. I'm quite new programmer and for SS as well.
I'm building my first web and i have some troubles with checkbox field. Everything looks good, but the problem is in CMS. If i check the value "DominaKeitimas" and do "save and publish" everything works except checkbox field in CMS. Somehow CMS do not save checked value in CMS, but in database and web it works perfectly. Search gives me everything i need and dataobject as well. So my question is: what did i do wrong and how to solute this issue?

some code...
<?php
class NTObjektas extends Page{
static $db = array( 'DominaKeitimas' => 'Boolean');
public static $has_one = array("Objects" =>"Object");
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Info', new CheckboxField('DominaKeitimas', 'Domina keitimas', 1));
/* some code */
return $fields;
}
}
class NTObjektas_Controller extends Page_Controller{
}

p.s. sorry for my broken english.

Avatar
zenmonkey

Community Member, 545 Posts

16 July 2013 at 3:28am

You're setting the value on the field which is overriding the set value on the CMS

change
$fields->addFieldToTab('Root.Info', new CheckboxField('DominaKeitimas', 'Domina keitimas', 1)); 
to
$fields->addFieldToTab('Root.Info', new CheckboxField('DominaKeitimas', 'Domina keitimas')); 

Avatar
Robke

Community Member, 4 Posts

16 July 2013 at 4:13am

Edited: 16/07/2013 4:14am

sorry, but its not working....
and i don't know why... there are some problems with DropdownField...

$veiksmoTipas = new DropdownField('VeiksmoTipas', 'some text', array(
'Siulome' => 'Siūlome',
'Ieskome' => 'Ieškome',
'Vystomi' => 'Vystomi Objektai'
));
this one works perfectly, but another is the same problem as with the checkbox field....

$sandorioTipas = new DropdownField('SandorioTipas', 'some text', array(
'Nuoma' => 'Nuoma',
'Pardavimas' => 'Pardavimas'
));
$sandorioTipas->setEmptyString('Pasirinkite');

$fields->addFieldToTab('Root.Info', $sandorioTipas);

values in the web and database are shown, but in CMS didn't saved.... strange

Avatar
Robke

Community Member, 4 Posts

19 July 2013 at 8:30pm

SOLVED:

i don't know what was wrong, but i changet my Variables names and all the things keep working :)