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.

Form Questions /

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

[SOLVED} Checkboxes In GridField


Go to End


2398 Views

Avatar
zenmonkey

Community Member, 545 Posts

20 February 2013 at 6:39am

Edited: 21/02/2013 7:59am

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