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.

Archive /

Our old forums are still available as a read-only archive.

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

DataObject defaults and CheckBoxField Questions


Reply


2 Posts   2187 Views

Avatar
zyko

Community Member, 66 Posts

23 April 2008 at 9:35am

I'm experiencing some troubles in defining a form for my from DataObject derived Class.

class MyClass1 extends DataObject {
...
static $defaults = array (
"MyTextField" == "MyValue"
"MyOption" => true
..
}
static $db = array(
"MyTextField" => "Varchar"
,"MyOption" => "Boolean"
)

i'm using this class within a
ManyManyComplexTableField relation of MyClass2
where i reference
$complex_field2 = new ManyManyComplexTableField(
$this ,'Class1List' ,'MyClass1 ' ,array('Name' => 'Name')
,'getCMSFields_forPopup'
);
$complex_field2->setParentClass('MyClass2');

First Try:
MyClass1
function getCMSFields_forPopup() {
$fields->push( new TextField('MyTextField','MyTextField'));
$fields->push( new CheckBoxField('MyOption','MyOption'));
...
}

Didn't show any Default Values on the form, as i expected.
So i think these 'Default values' will only be 'hot' when i create a new instance by code.
am i right here?
The behaviour on Page derived things is different there i think.

So i tryed:

function getCMSFields_forPopup() {
$fields->push( new TextField('MyTextField','MyTextField',self::$defaults['MyTextField']));
$fields->push( new CheckBoxField('MyOption','MyOption',self::$defaults['MyOption']));
...
}

which works fine for the Text Field. Now the Default Value is shown
but didn't help for the CheckBox.
Neither
$fields->push( new CheckBoxField('MyOption','MyOption',true));
Nor
$fields->push( new CheckBoxField('MyOption','MyOption',1));
nor
$fields->push( new CheckBoxField('MyOption','MyOption','1'));

does help.
the option is never preselected waht i wanted to be.

so i'm totally confused.
can anyone explain me what i'm doing wrong?
is there a bug in

ss 2.2.1

Avatar
zyko

Community Member, 66 Posts

23 April 2008 at 10:02am

mea culpa...

instead of
$fields->push( new CheckBoxField('MyOption','MyOption','1'));
i had
$fields->push( new CheckBoxField('MyOption','MyOption'),'1');

ARRGH.
time to go to bed now.....