formtools / core

The Form Tools Core.
https://formtools.org
207 stars 78 forks source link

Select and MultiSelect fields Group Fix #702

Open apmuthu opened 4 years ago

apmuthu commented 4 years ago

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.

alpaca-farm commented 1 year ago

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

apmuthu commented 1 year ago

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