1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-18 02:41:27 +02:00

feat(form-plugin): add tags field #360

This commit is contained in:
Awilum
2020-02-10 14:23:44 +03:00
parent 723010f3b0
commit ea249721f6
2 changed files with 20 additions and 13 deletions

View File

@@ -533,21 +533,17 @@ class FormController extends Controller
*/
protected function tagsField(string $field_id, string $field_name, $field_value, array $properties) : string
{
$title = isset($properties['title']) ? $properties['title'] : '';
$size = isset($properties['size']) ? $this->sizes[$properties['size']] : $this->sizes['12'];
$help = isset($properties['help']) ? $properties['help'] : '';
$title = isset($properties['title']) ? $properties['title'] : '';
$size = isset($properties['size']) ? $this->sizes[$properties['size']] : $this->sizes['12'];
$help = isset($properties['help']) ? $properties['help'] : '';
$options = isset($properties['options']) ? $properties['options'] : [];
$id = isset($properties['id']) ? $properties['id'] : $field_id;
$class = isset($properties['class']) ? $properties['class'] . $this->field_class : $this->field_class;
$name = isset($properties['name']) ? $properties['name'] : $field_name;
$current_value = isset($properties['value']) ? $properties['value'] : $field_value;
$attributes = isset($properties['attributes']) ? $properties['attributes'] : [];
$attributes['id'] = isset($attributes['id']) ? $attributes['id'] : $field_id;
$attributes['class'] = isset($attributes['class']) ? $attributes['class'] : $this->field_class;
return $this->flextype['view']->fetch('plugins/form/templates/fields/tags/field.html', ['title' => $title, 'size' => $size, 'name' => $name, 'id' => $id, 'class' => $class, 'help' => $help , 'options' => $options, 'current_value' => $current_value]);
$field = '<div class="form-group ' . $size . '">';
$field .= ($title ? Form::label($field_id, __($title)) : '');
$field .= '<input type="text" value="' . $field_value . '" name="' . $field_name . '" class="' . $attributes['class'] . '" data-role="tagsinput" />';
$field .= ($help ? '<small class="form-text text-muted">' . __($help) . '</small>' : '');
$field .= '</div>';
return $field;
}
/**

View File

@@ -0,0 +1,11 @@
<div class="form-group {{ size }}">
<label for="{{ id }}" class="form-control-title">{{ tr(title) }}</label>
<select class="{{ class }} js-tags" name="{{ name }}[]" multiple="multiple">
{% for key, value in current_value %}
<option value="{{ value }}" selected="selected">{{ value }}</option>
{% endfor %}
</select>
{% if help %}
<small>{{ help }}</small>
{% endif %}
</div>