Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-10910

function build_cfg_template() allow $size for $tpl_type = select

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.1.0-a3
    • 3.0.10
    • ACP
    • None

      I think it would be nice to be able to use the variable $size when the switch $tpl_type = 'select'

      Open "/adm/index.php"

      Find

      $tpl = '<select id="' . $key . '" name="' . $name . '">' . $return . '</select>';

      Replace by

      $size = (isset($tpl_type[1])) ? (int) $tpl_type[1] : 1;
       
      $tpl = '<select id="' . $key . '" name="' . $name . '"' . (($size) ? ' size="' . $size . '"' : '') . '>' . $return . '</select>';

      With this modification we can unselect a value without needed to create our own function for adding a choice like "No Value" or "None"

      How to use it ?

      In ACP file used the 'select' type as below :
      For example define the size to '8'

      $display_vars = array(
      	'title'	=> 'FOO_CONFIG',
      	'vars'	=> array(
      		'legend1'						=> 'FOO_SETTINGS',
      		'foo_group_id'	=> array('lang' => 'FOO_GROUP',		'validate' => 'int',	'type' => 'select:8', 'function' => 'group_select_options', 'params' => array('{CONFIG_VALUE}', false, false), 'explain' => true),
       
      		'legend4'				=> 'ACP_SUBMIT_CHANGES',
      	)
      );
      

      After, on submit, we check if no value is selected by using the following code

      // We go compare $display_vars with $cfg_array to determine if the type "select" does not have a choice selected.
      if ($submit)
      {
      	$display_vars_diff = array_diff_key($display_vars['vars'] , $cfg_array);
       
      	foreach ($display_vars_diff as $config_name_diff => $vars_diff)
      	{
      		if (strpos($vars_diff['type'], 'select') === false)
      		{
      			continue;
      		}
       
      		$cfg_array[$config_name_diff] = '';
      	}
      	unset($config_name_diff);
      }

            nickvergessen Joas Schilling
            Skouat Skouat
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: