Jump to:

1999 Posts in 1408 Topics by 613 members

Form Questions

SilverStripe Forums » Form Questions » Populating a form's CheckboxSetField

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

Page: 1
Go to End
Author Topic: 1431 Views
  • rob.s
    Avatar
    Community Member
    78 Posts

    Populating a form's CheckboxSetField Link to this post

    Hi,

    i have trouble generating a form that should pe prefilled with data.
    All fields are fine but the CheckboxSetField.

    I have a class "Request" (extended from DataObject ) that has a many_many relation to the class "Artistcategory"

    Now i want to show my "RequestForm" and populate the Data coming from a DataObject.

    public function RequestForm()
    {
    Validator::set_javascript_validation_handler('none');
    $form = new RequestForm($this, 'RequestForm');
    if( $this->_Request instanceof Request ) {
    $form->loadDataFrom ( $this->_Request);
    }
    return $form;
    }

    All fields are populated with the correct data of the dataobject.
    But not the CheckboxSetField. It's always empty (no Checkbox is ticked).

    Any ideas ?

    Class Request:

    class Request extends DataObject {
    public static $db = array(
    ..........
    );

    public static $many_many = array(
    'Artistcategories' => 'Artistcategory'
    );

    Class Artistcategory:

    class Artistcategory extends DataObject {
    public static $db = array(
    ......
    );

    public static $many_many = array(
    .......
    );

    public static $belongs_many_many = array(
    'Requests' => 'Request',
    );

    ]

  • cumquat
    Avatar
    Community Member
    189 Posts

    Re: Populating a form's CheckboxSetField Link to this post

    Hi ya,

    Did you get any luck with this as I'm stuck here too?

    Regards

    Mick

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: Populating a form's CheckboxSetField Link to this post

    if it helps this is how I create a CheckboxSetField with values and specify the ones currently selected...

    $dos = DataObject::get(<DataObjectName>);
    $map = $dos ? $map = $dos->toDropdownMap('ID','Name') : array();

    $selectedarr = array();
    $selectedarr[<ID>] = <ID>; //you would get this list from the relationship componentset with ->getIdList()

    $cbf = new CheckboxSetField(<FieldName>,<TabName>, $map,$selectedarr);

  • cumquat
    Avatar
    Community Member
    189 Posts

    Re: Populating a form's CheckboxSetField Link to this post

    Thanks for the help swaiba, i'm moving further on but am now stuck on how to save all the data including the checkbox data, i can get the standard data to save but not the many_many data. I had started another post here http://silverstripe.org/form-questions/show/16256 if you could help?

    Mick

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