updated bulmaformhelper to introduce field_select
This commit is contained in:
parent
c0f9ed1094
commit
9f7dab2a36
@ -9,6 +9,7 @@ class BulmaFormHelper extends \Prefab {
|
|||||||
|
|
||||||
const FIELD_INPUT = 10;
|
const FIELD_INPUT = 10;
|
||||||
const FIELD_TEXTAREA = 11;
|
const FIELD_TEXTAREA = 11;
|
||||||
|
const FIELD_SELECT = 13;
|
||||||
|
|
||||||
static public function render($node) {
|
static public function render($node) {
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ class BulmaFormHelper extends \Prefab {
|
|||||||
$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);
|
||||||
|
$selected = \Template::instance()->build($selected);
|
||||||
|
|
||||||
if(defined("BulmaFormHelper::$type")){
|
if(defined("BulmaFormHelper::$type")){
|
||||||
|
|
||||||
@ -53,6 +55,9 @@ class BulmaFormHelper extends \Prefab {
|
|||||||
case BulmaFormHelper::FIELD_TEXTAREA:
|
case BulmaFormHelper::FIELD_TEXTAREA:
|
||||||
return BulmaFormHelper::build_field_textarea($label, $name, $value, $class, $rows);
|
return BulmaFormHelper::build_field_textarea($label, $name, $value, $class, $rows);
|
||||||
break;
|
break;
|
||||||
|
case BulmaFormHelper::FIELD_SELECT:
|
||||||
|
return BulmaFormHelper::build_field_select($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;
|
||||||
@ -131,6 +136,65 @@ class BulmaFormHelper extends \Prefab {
|
|||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* build_field_select_new
|
||||||
|
*
|
||||||
|
* `<bulma type="H_FIELD_SELECT" label="Priority:" name="priority_id"
|
||||||
|
* options="priorities" option_value="id" option_name="name"
|
||||||
|
* selected="{{@ticket.priority_id}}"></bulma>`
|
||||||
|
*
|
||||||
|
* @param mixed $attr
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
static function build_field_select($attr)
|
||||||
|
{
|
||||||
|
$f3 = \Base::instance();
|
||||||
|
|
||||||
|
$class = $attr['class'] ?? '';
|
||||||
|
$label = $attr['label'] ?? '';
|
||||||
|
$name = $attr['name'] ?? '';
|
||||||
|
// $options_arr = $attr['options'] ?? [];
|
||||||
|
$option_value = $attr['option_value'] ?? 'id';
|
||||||
|
$option_name = $attr['option_name'] ?? 'name';
|
||||||
|
|
||||||
|
$options = \Template::instance()->token($attr['options']);
|
||||||
|
$selected = \Template::instance()->token($attr['selected']);
|
||||||
|
|
||||||
|
// TODO: label - this could be moved into a seperate function
|
||||||
|
$html_label = $label !== '' ? sprintf('<label class="label">%1$s</label>', $label) : '';
|
||||||
|
|
||||||
|
$tmp_options = '<?php echo \BulmaFormHelper::instance()->field_select('.
|
||||||
|
$options.', '.$selected.', "'.$option_value.'", "'.$option_name.'"); ?>';
|
||||||
|
|
||||||
|
$html = '
|
||||||
|
<div class="field %4$s">
|
||||||
|
%1$s
|
||||||
|
<div class="control">
|
||||||
|
<div class="select">
|
||||||
|
<select name="%3$s" id="%3$s">
|
||||||
|
%2$s
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return sprintf($html, $html_label, $tmp_options, $name, $class);
|
||||||
|
}
|
||||||
|
|
||||||
|
function field_select($options, $selected, $option_value, $option_name){
|
||||||
|
$html_options = '';
|
||||||
|
foreach ($options as $option) {
|
||||||
|
$value = $option[$option_value] ?? '';
|
||||||
|
$text = $option[$option_name] ?? '';
|
||||||
|
$html_selected = ((string)$value === (string)$selected) ? ' selected="selected"' : '';
|
||||||
|
$html_option = '<option value="%s"%s>%s</option>';
|
||||||
|
$html_options .= sprintf($html_option, $value, $html_selected, $text);
|
||||||
|
}
|
||||||
|
echo $html_options;
|
||||||
|
}
|
||||||
|
|
||||||
static function build_h_field_select_new($attr)
|
static function build_h_field_select_new($attr)
|
||||||
{
|
{
|
||||||
$f3 = \Base::instance();
|
$f3 = \Base::instance();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user