Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select and MultiSelect fields Group Fix #702

Open
apmuthu opened this issue May 1, 2020 · 0 comments
Open

Select and MultiSelect fields Group Fix #702

apmuthu opened this issue May 1, 2020 · 0 comments

Comments

@apmuthu
Copy link

@apmuthu apmuthu commented May 1, 2020

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 added a commit to apmuthu/formtools3 that referenced this issue May 2, 2020
formtools/core#702
formtools/core#699

For existing installs:
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';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.