/** * Set a minimum and maximum value to a field * * @param $min * @param $max */ public function setBetween($min, $max) { if ($this->field->isOfType('number') == 'min') { // min, max values for generation of the pattern $this->field->min($min); $this->field->max($max); } else { $this->field->pattern('.{' . $min . ',' . $max . '}'); // still let the browser limit text input after reaching the max $this->field->maxlength($max); } }
/** * Prints out the current tag * * @return string An input tag */ public function render() { // Particular case of the search element if ($this->isOfType('search')) { $this->asSearch(); } $this->setId(); // Render main input $input = parent::render(); // If we have a datalist to append, print it out if ($this->datalist) { $input .= $this->createDatalist($this->list, $this->datalist); } return $input; }
/** * Wrap a field with prepended and appended items * * @param Field $field * @param array $prepend * @param array $append * * @return string A field concatented with prepended and/or appended items */ public function prependAppend($field, $prepend, $append) { $class = array(); if ($prepend) { $class[] = 'input-prepend'; } if ($append) { $class[] = 'input-append'; } $return = '<div class="' . join(' ', $class) . '">'; $return .= join(null, $prepend); $return .= $field->render(); $return .= join(null, $append); $return .= '</div>'; return $return; }
/** * Wrap a field with prepended and appended items * * @param Field $field * @param array $prepend * @param array $append * * @return string A field concatented with prepended and/or appended items */ public function prependAppend($field, $prepend, $append) { $return = '<div>'; $return .= join(null, $prepend); $return .= $field->render(); $return .= join(null, $append); $return .= '</div>'; return $return; }
/** * Wrap a field with prepended and appended items * * @param Field $field * @param array $prepend * @param array $append * * @return string A field concatented with prepended and/or appended items */ public function prependAppend($field, $prepend, $append) { $return = '<div class="row collapse">'; foreach ($prepend as $item) { $return .= '<div class="large-2 small-3 columns"><span class="prefix">' . $item . '</span></div>'; } $return .= '<div class="large-10 small-9 columns">' . $field->render() . '</div>'; foreach ($append as $item) { $return .= '<div class="large-2 small-3 columns"><span class="postfix">' . $item . '</span></div>'; } $return .= '</div>'; return $return; }
/** * Create a label for a field * * @param Field $field * @param Element $label The field label if non provided * * @return string A label */ public function createLabelOf(Field $field, Element $label = null) { // Get the label and its informations if (!$label) { $label = $field->getLabel(); } // Get label "for" $for = $field->id ?: $field->getName(); // Get label text $text = $label->getValue(); if (!$text) { return false; } // Append required text if ($field->isRequired()) { $text .= $this->app['form']->getOption('required_text'); } // Render plain label if checkable, else a classic one $label->setValue($text); if (!$field->isCheckable()) { $label->for($for); } return $label; }
/** * Renders the select * * @return string A <select> tag */ public function render() { // Multiselects if ($this->isOfType('multiselect')) { if (!isset($this->attributes['id'])) { $this->setAttribute('id', $this->name); } $this->multiple(); $this->name .= '[]'; } if (!$this->value instanceof \ArrayAccess) { $this->value = (array) $this->value; } // Mark selected values as selected if ($this->hasChildren() and !empty($this->value)) { foreach ($this->value as $value) { if (is_object($value) && method_exists($value, 'getKey')) { $value = $value->getKey(); } $this->selectValue($value); } } // Add placeholder text if any if ($placeholder = $this->getPlaceholder()) { array_unshift($this->children, $placeholder); } $this->value = null; return parent::render(); }
/** * Wrap a field with prepended and appended items * * @param Field $field * @param array $prepend * @param array $append * * @return string A field concatented with prepended and/or appended items */ public function prependAppend($field, $prepend, $append) { $return = ''; foreach ($prepend as $item) { $return .= '<div class="two mobile-one columns"><span class="prefix">' . $item . '</span></div>'; } $return .= '<div class="ten mobile-three columns">' . $field->render() . '</div>'; foreach ($append as $item) { $return .= '<div class="two mobile-one columns"><span class="postfix">' . $item . '</span></div>'; } return $return; }
/** * Easier arguments order for hidden fields * * @param Container $app The Container * @param string $type hidden * @param string $name Field names * @param string $value Its value * @param array $attributes Attributes */ public function __construct(Container $app, $type, $name, $value, $attributes) { parent::__construct($app, $type, $name, '', $value, $attributes); }
/** * Prints out the current tag * * @return string An input file tag */ public function render() { // Maximum file size $hidden = $this->maxSize ? HtmlInput::hidden('MAX_FILE_SIZE', $this->maxSize) : null; return $hidden . parent::render(); }
/** * Apply methods to focused checkable * * @param string $method * @param array $parameters * * @return $this */ public function __call($method, $parameters) { $focused = $this->setOnFocused('attributes.' . $method, array_get($parameters, 0)); if ($focused) { return $this; } return parent::__call($method, $parameters); }