Created
October 10, 2015 15:13
-
-
Save tacone/035ac0eddeed92030659 to your computer and use it in GitHub Desktop.
Multiselect field with Zofe/Rapyd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 = " "; | |
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 . " </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