Fix missing pos for checkboxes
This commit is contained in:
50
ReadMe.md
50
ReadMe.md
@@ -43,7 +43,7 @@ Alternative setup composer local zip file repot:
|
||||
3) Upate the global `src/Extensions/DefaultExtension.php`:
|
||||
1) `getFunctionHandler`: popup_init, popup
|
||||
2) `getBlockHandler`: t
|
||||
4) check either `src/FunctionHander/HtmlCheckboxes.php` and `src/FunctionHander/HtmlOptions.php` have changed
|
||||
4) check either `src/FunctionHander/HtmlCheckboxes.php`, `src/FunctionHander/HtmlOptions.php` and `src/FunctionHander/HtmlBase.php` have changed
|
||||
1) Update and leep the label/pos changes
|
||||
5) Create new release version as official relase number
|
||||
|
||||
@@ -84,6 +84,42 @@ Then open the vscode settings and set for the Folder (if multiple folders are in
|
||||
|
||||
### Changed
|
||||
|
||||
- `src/FunctionHander/HtmlBase.php`
|
||||
|
||||
```diff
|
||||
diff --git i/src/FunctionHandler/HtmlBase.php w/src/FunctionHandler/HtmlBase.php
|
||||
index 99f8e6c..99a82a6 100644
|
||||
--- i/src/FunctionHandler/HtmlBase.php
|
||||
+++ w/src/FunctionHandler/HtmlBase.php
|
||||
@@ -16,6 +16,7 @@ class HtmlBase extends Base {
|
||||
* @param $labels
|
||||
* @param $label_ids
|
||||
* @param bool $escape
|
||||
+ * @param $pos [default='']
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -30,7 +31,8 @@ class HtmlBase extends Base {
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
- $escape = true
|
||||
+ $escape = true,
|
||||
+ $pos = ''
|
||||
) {
|
||||
|
||||
$_output = '';
|
||||
@@ -83,7 +85,7 @@ class HtmlBase extends Base {
|
||||
}
|
||||
$_output .= '<input type="' . $inputType . '" name="' . $name;
|
||||
if ($ismultiselect) {
|
||||
- $_output .= '[]';
|
||||
+ $_output .= '[' . $pos . ']';
|
||||
}
|
||||
$_output .= '" value="' . $value . '"';
|
||||
if ($labels && $label_ids) {
|
||||
```
|
||||
|
||||
- `src/FunctionHander/HtmlCheckboxes.php`
|
||||
|
||||
```diff
|
||||
@@ -127,8 +163,10 @@ Then open the vscode settings and set for the Folder (if multiple folders are in
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
+ $_pos,
|
||||
$escape
|
||||
- $_pos,
|
||||
- $escape
|
||||
+ $escape,
|
||||
+ $_pos
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -142,8 +180,10 @@ Then open the vscode settings and set for the Folder (if multiple folders are in
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
+ $_pos,
|
||||
$escape
|
||||
- $_pos,
|
||||
- $escape
|
||||
+ $escape,
|
||||
+ $_pos
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -16,6 +16,7 @@ class HtmlBase extends Base {
|
||||
* @param $labels
|
||||
* @param $label_ids
|
||||
* @param bool $escape
|
||||
* @param $pos [default='']
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -30,7 +31,8 @@ class HtmlBase extends Base {
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
$escape = true
|
||||
$escape = true,
|
||||
$pos = ''
|
||||
) {
|
||||
|
||||
$_output = '';
|
||||
@@ -83,7 +85,7 @@ class HtmlBase extends Base {
|
||||
}
|
||||
$_output .= '<input type="' . $inputType . '" name="' . $name;
|
||||
if ($ismultiselect) {
|
||||
$_output .= '[]';
|
||||
$_output .= '[' . $pos . ']';
|
||||
}
|
||||
$_output .= '" value="' . $value . '"';
|
||||
if ($labels && $label_ids) {
|
||||
|
||||
@@ -163,8 +163,8 @@ class HtmlCheckboxes extends HtmlBase {
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
$_pos,
|
||||
$escape
|
||||
$escape,
|
||||
$_pos
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -183,8 +183,8 @@ class HtmlCheckboxes extends HtmlBase {
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
$_pos,
|
||||
$escape
|
||||
$escape,
|
||||
$_pos
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,22 +70,37 @@ BASE: {$BASE}<br>
|
||||
<div>LOOP OUTPUT: {$smarty.section.page_list.index}</div>
|
||||
{/section}
|
||||
</div>
|
||||
<div>
|
||||
Drop Down simple
|
||||
</div>
|
||||
<div>
|
||||
<select id="drop_down_test" name="drop_down_test">
|
||||
{html_options options=$drop_down_test selected=$drop_down_test_selected}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
Drop Down nested
|
||||
</div>
|
||||
<div>
|
||||
<select id="drop_down_test_nested" name="drop_down_test_nested">
|
||||
{html_options options=$drop_down_test_nested selected=$drop_down_test_nested_selected}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
radio plain
|
||||
</div>
|
||||
<div>
|
||||
{html_radios name="radio_test" options=$radio_test selected=$radio_test_selected}
|
||||
</div>
|
||||
<div>
|
||||
checkbox plain
|
||||
</div>
|
||||
<div>
|
||||
{html_checkboxes name="checkbox_test" options=$checkbox_test selected=$checkbox_test_selected}
|
||||
</div>
|
||||
<div>
|
||||
checkbox pos
|
||||
</div>
|
||||
<div>
|
||||
{html_checkboxes name="checkbox_test_pos" options=$checkbox_test selected=$checkbox_test_pos_selected pos=$checkbox_test_pos}
|
||||
</div>
|
||||
|
||||
@@ -62,22 +62,37 @@ BASE: {$BASE}<br>
|
||||
<div>LOOP OUTPUT: {$smarty.section.page_list.index}</div>
|
||||
{/section}
|
||||
</div>
|
||||
<div>
|
||||
Drop Down simple
|
||||
</div>
|
||||
<div>
|
||||
<select id="drop_down_test" name="drop_down_test">
|
||||
{html_options options=$drop_down_test selected=$drop_down_test_selected}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
Drop Down nested
|
||||
</div>
|
||||
<div>
|
||||
<select id="drop_down_test_nested" name="drop_down_test_nested">
|
||||
{html_options options=$drop_down_test_nested selected=$drop_down_test_nested_selected}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
radio plain
|
||||
</div>
|
||||
<div>
|
||||
{html_radios name="radio_test" options=$radio_test selected=$radio_test_selected}
|
||||
</div>
|
||||
<div>
|
||||
checkbox plain
|
||||
</div>
|
||||
<div>
|
||||
{html_checkboxes name="checkbox_test" options=$checkbox_test selected=$checkbox_test_selected}
|
||||
</div>
|
||||
<div>
|
||||
checkbox pos
|
||||
</div>
|
||||
<div>
|
||||
{html_checkboxes name="checkbox_test_pos" options=$checkbox_test selected=$checkbox_test_pos_selected pos=$checkbox_test_pos}
|
||||
</div>
|
||||
|
||||
109
update/src/FunctionHandler/HtmlBase.php
Normal file
109
update/src/FunctionHandler/HtmlBase.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Smarty\FunctionHandler;
|
||||
|
||||
class HtmlBase extends Base {
|
||||
|
||||
/**
|
||||
* @param $inputType
|
||||
* @param $name
|
||||
* @param $value
|
||||
* @param $output
|
||||
* @param $ismultiselect
|
||||
* @param $selected
|
||||
* @param $extra
|
||||
* @param $separator
|
||||
* @param $labels
|
||||
* @param $label_ids
|
||||
* @param bool $escape
|
||||
* @param $pos [default='']
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getHtmlForInput(
|
||||
$inputType,
|
||||
$name,
|
||||
$value,
|
||||
$output,
|
||||
$ismultiselect,
|
||||
$selected,
|
||||
$extra,
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
$escape = true,
|
||||
$pos = ''
|
||||
) {
|
||||
|
||||
$_output = '';
|
||||
if (is_object($value)) {
|
||||
if (method_exists($value, '__toString')) {
|
||||
$value = (string)$value->__toString();
|
||||
} else {
|
||||
trigger_error(
|
||||
'value is an object of class \'' . get_class($value) .
|
||||
'\' without __toString() method',
|
||||
E_USER_NOTICE
|
||||
);
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
$value = (string)$value;
|
||||
}
|
||||
if (is_object($output)) {
|
||||
if (method_exists($output, '__toString')) {
|
||||
$output = (string)$output->__toString();
|
||||
} else {
|
||||
trigger_error(
|
||||
'output is an object of class \'' . get_class($output) .
|
||||
'\' without __toString() method',
|
||||
E_USER_NOTICE
|
||||
);
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
$output = (string)$output;
|
||||
}
|
||||
if ($labels) {
|
||||
if ($label_ids) {
|
||||
$_id = smarty_function_escape_special_chars(
|
||||
preg_replace(
|
||||
'![^\w\-\.]!' . \Smarty\Smarty::$_UTF8_MODIFIER,
|
||||
'_',
|
||||
$name . '_' . $value
|
||||
)
|
||||
);
|
||||
$_output .= '<label for="' . $_id . '">';
|
||||
} else {
|
||||
$_output .= '<label>';
|
||||
}
|
||||
}
|
||||
$name = smarty_function_escape_special_chars($name);
|
||||
$value = smarty_function_escape_special_chars($value);
|
||||
if ($escape) {
|
||||
$output = smarty_function_escape_special_chars($output);
|
||||
}
|
||||
$_output .= '<input type="' . $inputType . '" name="' . $name;
|
||||
if ($ismultiselect) {
|
||||
$_output .= '[' . $pos . ']';
|
||||
}
|
||||
$_output .= '" value="' . $value . '"';
|
||||
if ($labels && $label_ids) {
|
||||
$_output .= ' id="' . $_id . '"';
|
||||
}
|
||||
if ($ismultiselect && is_array($selected)) {
|
||||
if (isset($selected[ $value ])) {
|
||||
$_output .= ' checked="checked"';
|
||||
}
|
||||
} elseif ($value === $selected) {
|
||||
$_output .= ' checked="checked"';
|
||||
}
|
||||
$_output .= $extra . ' />' . $output;
|
||||
if ($labels) {
|
||||
$_output .= '</label>';
|
||||
}
|
||||
$_output .= $separator;
|
||||
return $_output;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -163,8 +163,8 @@ class HtmlCheckboxes extends HtmlBase {
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
$_pos,
|
||||
$escape
|
||||
$escape,
|
||||
$_pos
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -183,8 +183,8 @@ class HtmlCheckboxes extends HtmlBase {
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
$_pos,
|
||||
$escape
|
||||
$escape,
|
||||
$_pos
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user