core icon indicating copy to clipboard operation
core copied to clipboard

Select and MultiSelect fields Group Fix

Open apmuthu opened this issue 5 years ago • 2 comments

FormTools v3.0.20

The optgroup code is not generated as there is a typo in the variable name in the smarty template code.

Smarty v2 syntax is still used in FT 3 and is available for foreach command at: https://www.smarty.net/docsv2/en/language.function.foreach.tpl

However, FormTools v3 still relies on the old syntax though it now uses Smarty 3.x library.

The files at: global\code\field_types\Dropdown.class.php global\code\field_types\MultiSelect.class.php should have the variable $group_info["name"] replaced with $group_info["group_name"].

These files were used in FormTools v2 but are still there for maybe compatibility reasons of some modules. They are now superseded by having the templates stored in the database table field_types.

Consequently, the following sql statements need to be executed for existing installs to effect the above variable replacement (suitably edited for your table prefix):

UPDATE `ft_field_types` SET `edit_field_smarty_markup` = '{if $contents == \"\"}\n  <div class=\"cf_field_comments\">\n    {$LANG.phrase_not_assigned_to_option_list}\n  </div>\n{else}\n  <select name=\"{$NAME}\">\n    {foreach from=$contents.options item=curr_group_info name=group}\n      {assign var=group_info value=$curr_group_info.group_info}\n      {assign var=options value=$curr_group_info.options}\n      {if array_key_exists(\"group_name\", $group_info) && !empty($group_info[\"group_name\"])}\n      <optgroup label=\"{$group_info.group_name|escape}\">\n      {/if}\n      {foreach from=$options item=option name=row}\n        <option value=\"{$option.option_value}\"\n          {if $VALUE == $option.option_value}selected{/if}>{$option.option_name}</option>\n      {/foreach}\n      {if array_key_exists(\"group_name\", $group_info) && !empty($group_info[\"group_name\"])}\n      </optgroup>\n      {/if}\n    {/foreach}\n  </select>\n{/if}\n{if $comments}\n  <div class=\"cf_field_comments\">{$comments}</div>\n{/if}' WHERE `field_type_id` = '4'; 
UPDATE `ft_field_types` SET `edit_field_smarty_markup` = '{if $contents == \"\"}\n  <div class=\"cf_field_comments\">{$LANG.phrase_not_assigned_to_option_list}</div>\n{else}\n  {assign var=vals value=\"`$g_multi_val_delimiter`\"|explode:$VALUE}\n  <select name=\"{$NAME}[]\" multiple size=\"{if $num_rows}{$num_rows}{else}5{/if}\">\n  {foreach from=$contents.options item=curr_group_info name=group}\n    {assign var=group_info value=$curr_group_info.group_info}\n    {assign var=options value=$curr_group_info.options}\n    {if array_key_exists(\"group_name\", $group_info) && !empty($group_info[\"group_name\"])}\n    <optgroup label=\"{$group_info.group_name|escape}\">\n    {/if}\n    {foreach from=$options item=option name=row}\n      <option value=\"{$option.option_value}\" {if $option.option_value|in_array:$vals}selected{/if}>{$option.option_name}</option>\n    {/foreach}\n    {if array_key_exists(\"group_name\", $group_info) && !empty($group_info[\"group_name\"])}\n    </optgroup>\n    {/if}\n  {/foreach}\n  </select>\n{/if}\n\n{if $comments}\n  <div class=\"cf_field_comments\">{$comments}</div>\n{/if}' WHERE `field_type_id` = '5'; 

This enables the use of grouped selects and multi selects.

For new installs, the installer sql may need to be changed accordingly unless the information is sucked into the table from the above files.

apmuthu avatar May 01 '20 21:05 apmuthu

Thank you for pointing out where this can be fixed in existing installs. I was lost trying to pinpoint why optgroups weren't showing in groups for dropdowns (was previously using an older version that did not have the issue).

This is still a bug in 3.1.1

alpaca-farm avatar Jun 08 '23 20:06 alpaca-farm

Smarty v3.1.31 (14.12.2016) is used in FormTools v3.1.1. The fixes for vFT3.1.1 is here: FT3.1.1_fixes_global-code-field_types.zip

apmuthu avatar Jul 20 '23 09:07 apmuthu