Skip to content

Instantly share code, notes, and snippets.

@tacone
Created October 10, 2015 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tacone/035ac0eddeed92030659 to your computer and use it in GitHub Desktop.
Save tacone/035ac0eddeed92030659 to your computer and use it in GitHub Desktop.
Multiselect field with Zofe/Rapyd
<?php namespace Zofe\Rapyd\DataForm\Field;
use Illuminate\Support\Facades\Form;
class Multiselect extends Field
{
public $type = "checks";
public $multiple = true;
public $size = null;
public $description = "";
public $separator = "&nbsp;&nbsp;";
public $format = "%s";
public $css_class = "multiselect";
public $checked_value = 1;
public $unchecked_value = 0;
public $clause = "wherein";
public function getValue()
{
parent::getValue();
$this->values = explode($this->serialization_sep, $this->value);
$description_arr = array();
foreach ($this->options as $value => $description) {
if (in_array($value, $this->values)) {
$description_arr[] = $description;
}
}
$this->description = implode($this->separator, $description_arr);
}
public function build()
{
$output = "";
if (!isset($this->style)) {
$this->style = "margin:0 2px 0 0; vertical-align: middle";
}
unset($this->attributes['id']);
if (parent::build() === false) {
return;
}
switch ($this->status) {
case "disabled":
case "show":
if (!isset($this->value)) {
$output = $this->layout['null_label'];
} else {
$output = $this->description;
}
$output = "<div class='help-block'>" . $output . "&nbsp;</div>";
break;
case "create":
case "modify":
$this->attributes['multiple'] = 'multiple';
$output .= \Form::select($this->name . '[]', $this->options, $this->values, $this->attributes);
$output .= $this->extra_output;
break;
case "hidden":
$output = Form::hidden($this->name, $this->value);
break;
default:
}
$this->output = $output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment