updated BulmaFormHelper with H_FIELD_SELECT_NEW - allowing the creation of horizontal fields using template extension

This commit is contained in:
tp_dhu 2025-03-25 09:16:32 +00:00
parent 369f22444e
commit bd9ddfb0d2

View File

@ -5,21 +5,26 @@ class BulmaFormHelper extends \Prefab {
const H_FIELD_INPUT = 1; const H_FIELD_INPUT = 1;
const H_FIELD_TEXTAREA = 2; const H_FIELD_TEXTAREA = 2;
const H_FIELD_SELECT = 3; 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 * // all *
$label = $args['@attrib']['label']; $label = $attr['label'];
$name = $args['@attrib']['name']; $name = $attr['name'];
$value = isset($args['@attrib']['value']) ? $args['@attrib']['value'] : ''; $value = isset($attr['value']) ? $attr['value'] : '';
// select // select
$options = isset($args['@attrib']['options']) ? $args['@attrib']['options'] : ''; $options = isset($attr['options']) ? $attr['options'] : '';
$selected = isset($args['@attrib']['selected']) ? $args['@attrib']['selected'] : ''; $selected = isset($attr['selected']) ? $attr['selected'] : '';
// //
$label = \Template::instance()->build($label); $label = \Template::instance()->build($label);
$name = \Template::instance()->build($name); $name = \Template::instance()->build($name);
$value = \Template::instance()->build($value); $value = \Template::instance()->build($value);
$options_array = \Template::instance()->token($options);
if(defined("BulmaFormHelper::$type")){ if(defined("BulmaFormHelper::$type")){
@ -35,6 +40,9 @@ class BulmaFormHelper extends \Prefab {
case BulmaFormHelper::H_FIELD_SELECT: case BulmaFormHelper::H_FIELD_SELECT:
return BulmaFormHelper::build_h_field_select($label, $name, $options, $selected); return BulmaFormHelper::build_h_field_select($label, $name, $options, $selected);
break; break;
case BulmaFormHelper::H_FIELD_SELECT_NEW:
return BulmaFormHelper::build_h_field_select_new($attr);
break;
default: default:
return '<div class="notification is-danger">Error: Bulma CSS Form TYPE ('.$type.') not defined.</div>'; return '<div class="notification is-danger">Error: Bulma CSS Form TYPE ('.$type.') not defined.</div>';
break; 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){ static function build_h_field_input($label, $name, $value){
$string = ' $string = '
<div class="field is-horizontal"> <div class="field is-horizontal">