Example #1
0
 /**
  * Easier arguments order for hidden fields
  *
  * @param string $type       hidden
  * @param string $name       Field name
  * @param string $value      Its value
  * @param array  $attributes Attributes
  */
 public function __construct($type, $name, $label, $value, $attributes)
 {
     parent::__construct($type, $name, $label, $value, $attributes);
     // Multiple files field
     if ($this->type == 'files') {
         $this->multiple();
         $this->type = 'file';
         $this->name = $this->name . '[]';
     }
 }
Example #2
0
 /**
  * Easier arguments order for selects
  *
  * @param string $type       select or multiselect
  * @param string $name       Field name
  * @param string $label      Field label
  * @param array  $options    Its options
  * @param mixed  $selected   Selected entry
  * @param array  $attributes Attributes
  */
 public function __construct($type, $name, $label, $options, $selected, $attributes)
 {
     if ($options) {
         $this->options = $options;
     }
     if ($selected) {
         $this->value = $selected;
     }
     parent::__construct($type, $name, $label, $selected, $attributes);
 }
Example #3
0
 public function __construct($type, $name, $label, $value, $attributes)
 {
     parent::__construct($type, $name, $label, $value, $attributes);
     // Multiple models population
     if (is_array($this->value)) {
         foreach ($this->value as $v) {
             $_value[] = is_object($v) ? $v->__toString() : $v;
         }
         $this->value = implode(', ', $_value);
     }
 }
Example #4
0
 /**
  * Easier arguments order for selects
  *
  * @param string $type       select or multiselect
  * @param string $name       Field name
  * @param string $label      Field label
  * @param array  $options    Its options
  * @param mixed  $selected   Selected entry
  * @param array  $attributes Attributes
  */
 public function __construct($type, $name, $label, $options, $selected, $attributes)
 {
     if ($options) {
         $this->options = $options;
     }
     if ($selected) {
         $this->value = $selected;
     }
     parent::__construct($type, $name, $label, $selected, $attributes);
     // Multiple models population
     if (is_array($this->value)) {
         $this->fromQuery($this->value);
         $this->value = $selected ?: null;
     }
 }
Example #5
0
 /**
  * Creates a field for a label
  *
  * @param Field $field The field
  * @return string A field label
  */
 public static function label($field, $label = null)
 {
     // Get the label and its informations
     if (!$label) {
         $label = $field->label;
     }
     $attributes = array_get($label, 'attributes', array());
     $label = array_get($label, 'label');
     if (!$label) {
         return false;
     }
     // Append required text
     if ($field->isRequired()) {
         $label .= Config::get('required_text');
     }
     // Get the field name to link the label to it
     if ($field->isCheckable()) {
         return '<label' . HTML::attributes($attributes) . '>' . $label . '</label>';
     }
     return HTML::decode(Form::label($field->name, $label, $attributes));
 }
Example #6
0
 /**
  * Easier arguments order for hidden fields
  *
  * @param string $type       hidden
  * @param string $name       Field name
  * @param string $value      Its value
  * @param array  $attributes Attributes
  */
 public function __construct($type, $name, $value, $attributes)
 {
     parent::__construct($type, $name, '', $value, $attributes);
 }