updated BulmaFormHelper with H_FIELD_SELECT_NEW - allowing the creation of horizontal fields using template extension
This commit is contained in:
parent
369f22444e
commit
bd9ddfb0d2
@ -5,21 +5,26 @@ class BulmaFormHelper extends \Prefab {
|
||||
const H_FIELD_INPUT = 1;
|
||||
const H_FIELD_TEXTAREA = 2;
|
||||
const H_FIELD_SELECT = 3;
|
||||
const H_FIELD_SELECT_NEW = 4;
|
||||
|
||||
static public function render($args) {
|
||||
static public function render($node) {
|
||||
|
||||
$attr = $node['@attrib'] ?? [];
|
||||
$type = strtoupper($attr['type']) ?? null;
|
||||
|
||||
$type = strtoupper($args['@attrib']['type']);
|
||||
// all *
|
||||
$label = $args['@attrib']['label'];
|
||||
$name = $args['@attrib']['name'];
|
||||
$value = isset($args['@attrib']['value']) ? $args['@attrib']['value'] : '';
|
||||
$label = $attr['label'];
|
||||
$name = $attr['name'];
|
||||
$value = isset($attr['value']) ? $attr['value'] : '';
|
||||
// select
|
||||
$options = isset($args['@attrib']['options']) ? $args['@attrib']['options'] : '';
|
||||
$selected = isset($args['@attrib']['selected']) ? $args['@attrib']['selected'] : '';
|
||||
$options = isset($attr['options']) ? $attr['options'] : '';
|
||||
$selected = isset($attr['selected']) ? $attr['selected'] : '';
|
||||
//
|
||||
|
||||
$label = \Template::instance()->build($label);
|
||||
$name = \Template::instance()->build($name);
|
||||
$value = \Template::instance()->build($value);
|
||||
$options_array = \Template::instance()->token($options);
|
||||
|
||||
if(defined("BulmaFormHelper::$type")){
|
||||
|
||||
@ -35,6 +40,9 @@ class BulmaFormHelper extends \Prefab {
|
||||
case BulmaFormHelper::H_FIELD_SELECT:
|
||||
return BulmaFormHelper::build_h_field_select($label, $name, $options, $selected);
|
||||
break;
|
||||
case BulmaFormHelper::H_FIELD_SELECT_NEW:
|
||||
return BulmaFormHelper::build_h_field_select_new($attr);
|
||||
break;
|
||||
default:
|
||||
return '<div class="notification is-danger">Error: Bulma CSS Form TYPE ('.$type.') not defined.</div>';
|
||||
break;
|
||||
@ -46,6 +54,40 @@ class BulmaFormHelper extends \Prefab {
|
||||
|
||||
}
|
||||
|
||||
static function build_h_field_select_new($attr)
|
||||
{
|
||||
$f3 = \Base::instance();
|
||||
|
||||
$label = $attr['label'] ?? '';
|
||||
$name = $attr['name'] ?? '';
|
||||
$options_arr = $attr['options'] ?? [];
|
||||
$optionValue = $attr['option_value'] ?? 'id';
|
||||
$optionName = $attr['option_name'] ?? 'name';
|
||||
$selected = $attr['selected'] ?? '';
|
||||
|
||||
$options = $f3->get($options_arr);
|
||||
|
||||
$html = '<div class="field is-horizontal"><div class="field-label is-normal">';
|
||||
if (!empty($label)) {
|
||||
$html .= '<label class="label">'.$label.'</label>';
|
||||
}
|
||||
$html .= '</div><div class="field-body"><div class="field">';
|
||||
$html .= '<div class="select">';
|
||||
$html .= '<select name="'.$name.'">';
|
||||
|
||||
foreach ($options as $option) {
|
||||
$value = $option[$optionValue] ?? '';
|
||||
$text = $option[$optionName] ?? '';
|
||||
$sel = ((string)$value === (string)$selected) ? ' selected="selected"' : '';
|
||||
$html .= '<option value="'.$value.'"'.$sel.'>'.$text.'</option>';
|
||||
}
|
||||
|
||||
$html .= '</select>';
|
||||
$html .= '</div></div></div></div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
static function build_h_field_input($label, $name, $value){
|
||||
$string = '
|
||||
<div class="field is-horizontal">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user