Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » DataObject defaults and CheckBoxField Questions

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

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

Page: 1
Go to End
Author Topic: 2096 Views
  • zyko
    Avatar
    Community Member
    66 Posts

    DataObject defaults and CheckBoxField Questions Link to this post

    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

  • zyko
    Avatar
    Community Member
    66 Posts

    Re: DataObject defaults and CheckBoxField Questions Link to this post

    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.....

    2096 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.