Jump to:

1970 Posts in 1275 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » [SOLVED} Checkboxes In GridField

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

Page: 1
Go to End
Author Topic: 553 Views
  • zenmonkey
    Avatar
    Community Member
    524 Posts

    [SOLVED} Checkboxes In GridField Link to this post

    I'm trying to create a form where a user can email selected files from a GridField, I had done something like this back in he day with a TableList Field, but I'm not sure how to augment teh gridfield witha column of checboxes, that the Submit action iterate through

    Any guidance would be helpful

    EDIT

    I figured it out, I created the following GridField Componant:

    class GridFieldSelectBox implements GridField_ColumnProvider {
       
       
       public function __construct($useToggle = true, $targetFragment = 'before') {
          $this->targetFragment = $targetFragment;
          $this->useToggle = $useToggle;
       }
       
       public function augmentColumns($field, &$cols) {
          if(!in_array('Select', $cols)) $cols[] = 'Select';
       }
       
       public function getColumnsHandled($field) {
          return array('Select');
       }
       
       public function getColumnContent($field, $record, $col) {
          if($record->canView()) {
             $data = new ArrayData(array(
                'ID' => $record->ID
             ));
             return $data->renderWith('GridFieldSelectItem');
          }
       }
       
       public function getColumnAttributes($field, $record, $col) {
          return array('class' => 'col-select');
       }

       public function getColumnMetadata($gridField, $col) {
          return array('title' => "Select");
       }
       
       
    }


    and this template to render the checkbox

    <input id="File_$ID" class="checkbox" name="AttachedFiles[]" type="checkbox" value="$ID" />

    I then added to the gridfield on the front end and I can iterate throught $data["AttachedFiles"] on the form action

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