[2.1 RC3][2.0.18] Width of setting field type "large_text" is always the same

Started by davidhs, February 18, 2021, 08:08:14 AM

Previous topic - Next topic

davidhs

In "Administration Center > Configuration > Modification Settings" mods can add different fields.

2.1 RC3: Width = 100%

In my case, I have a mod that add a setting field with type "large_text" (a textarea button):
$config_vars = array();
$config_vars[] = array('title', 'mwll');
$config_vars[] = array('large_text', 'mwll_code', 20,
'subtext' => $txt['mwll_code_desc'],
'preinput' =>
'<tt>function (&amp;$buttons)<br />' .
'{<br />' .
'&nbsp;&nbsp;global $txt, $smcFunc, $scripturl, $modSettings, $user_info;<br />' .
'&nbsp;&nbsp;</tt>',
'postinput' => '<br /><tt>}</tt>',
'cols' => 20,
);

I added 'cols' key here but in my mod I did not add this key because it is not used :( . And it is not used because there is a CSS code who change width to 100% (see image textarea_100.png):
Code (Themes\default\css\index.css (line 102)) Select
#quick_edit_body_container textarea,
.move_topic textarea,
dd textarea {
width: 100%; /* This is "my problem": Correct in many cases but not in mine. */
min-height: 100px;
}

Really I do not want use cols = 20, I want width: 90%. (see image textarea_90.png)

Now there is this code:
Code (Themes\default\Admin.template.php (line 929)) Select

// Text area?
elseif ($config_var['type'] == 'large_text')
echo '
<textarea rows="', (!empty($config_var['size']) ? $config_var['size'] : (!empty($config_var['rows']) ? $config_var['rows'] : 4)), '" cols="', (!empty($config_var['cols']) ? $config_var['cols'] : 30), '" ', $javascript, $disabled, ' name="', $config_var['name'], '" id="', $config_var['name'], '">', $config_var['value'], '</textarea>';


If you add a key 'style' in this or more setting field,
Code (Themes\default\Admin.template.php (line 929)) Select
// Text area?
elseif ($config_var['type'] == 'large_text')
echo '
<textarea rows="', (!empty($config_var['size']) ? $config_var['size'] : (!empty($config_var['rows']) ? $config_var['rows'] : 4)), '" cols="', (!empty($config_var['cols']) ? $config_var['cols'] : 30), '" ', (!empty($config_var['style']) ? 'style="' . $config_var['style'] . '"' : ''), $javascript, $disabled, ' name="', $config_var['name'], '" id="', $config_var['name'], '">', $config_var['value'], '</textarea>';


we can write
$config_vars = array();
$config_vars[] = array('title', 'mwll');
$config_vars[] = array('large_text', 'mwll_code', 20,
'subtext' => $txt['mwll_code_desc'],
'preinput' =>
'<tt>function (&amp;$buttons)<br />' .
'{<br />' .
'&nbsp;&nbsp;global $txt, $smcFunc, $scripturl, $modSettings, $user_info;<br />' .
'&nbsp;&nbsp;</tt>',
'postinput' => '<br /><tt>}</tt>',
'cols' => 20,
'style' => 'width: 90%;',
);





2.0.18: Width = 30 columns

There is a similar case, now width is always COL=30 (see image textarea_30.png)
Code (Themes\default\Admin.template.php (line 913)) Select
// Text area?
elseif ($config_var['type'] == 'large_text')
echo '
<textarea rows="', ($config_var['size'] ? $config_var['size'] : 4), '" cols="30" ', $javascript, $disabled, ' name="', $config_var['name'], '" id="', $config_var['name'], '">', $config_var['value'], '</textarea>';

If you add a key 'style' in this or more setting field,
Code (Themes\default\Admin.template.php (line 913)) Select
// Text area?
elseif ($config_var['type'] == 'large_text')
echo '
<textarea rows="', ($config_var['size'] ? $config_var['size'] : 4), '" cols="30" ', (!empty($config_var['style']) ? 'style="' . $config_var['style'] . '"' : ''), $javascript, $disabled, ' name="', $config_var['name'], '" id="', $config_var['name'], '">', $config_var['value'], '</textarea>';

the problem is fixed.


davidhs

Quote from: live627 on February 19, 2021, 01:10:10 AM
So add a CSS override
Yes, I know, I can modify index.css but I think will be more easy if mod creators can set width of this field without modify index.css (width 100% is a good idea in majory of cases but not in all).

By other hand... If I can set 'cols' (in 2.1) and forum always sets width 100%, it is nonsense. In my opinion, the best is:
- set width 100% in index.css (as 2.1, valid in majory of cases).
- remove parameter 'cols' and set cols=constant value (as 2.0.x, because CSS override this value of cols and this will be not used).
- add paramter 'style' to set inline style. This override style of index.css because has more priority.

Kindred

SO, not technically a bug..... since it is working as intended.

As we are not making any enhancements in the 2.0.x line and the 2.1 is in RC pending a release and probably won't get further enhancements, especially in things like settings, I believe that - if you want this available to others - it is something that you could apply as a mod
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

davidhs

Quote from: Kindred on February 19, 2021, 10:32:22 AM
SO, not technically a bug..... since it is working as intended.
It is true... in part (in my opinion!):

  • In 2.0.x series this is an enhancement, of course. Value is a constant and I want change this.
  • But in 2.1 is a bug of design, small and unimportant, of course.
    Why? Because there is a key 'cols', used in source code, and this value is override by index.css. If a mod write
    <textarea cols=30>
    and default theme use width 100%, this an unexpected behavior (from the viewpoint of the mod). Else... why add the key 'cols'?
    Of course anybody can create a theme that override 'cols' but I think the default theme must use 'cols' if it is set.

Quote from: Kindred on February 19, 2021, 10:32:22 AM
As we are not making any enhancements in the 2.0.x line and the 2.1 is in RC pending a release and probably won't get further enhancements, especially in things like settings, I believe that - if you want this available to others - it is something that you could apply as a mod
Really this is an unimportant problem and perhaps maybe solved in next versions of 2.1 (RC4, RC5,... 2.1.1, 2.1.2). I do not know if it is worth making a mod to change only one line. :o

live627

You probably don't need to modify index.css since you can add inline CSS to the HTML page via addInlineCss()

davidhs

Quote from: live627 on February 20, 2021, 11:58:19 PM
You probably don't need to modify index.css since you can add inline CSS to the HTML page via addInlineCss()
Yes, thank you! I searched something like this but I did not find :( when I upgrade my mod. Also I found how to do this in 2.0 series.
Code (2.0 series) Select
$context['html_headers'] .= '
<style type="text/css">
textarea#mwll_code { width: 90%; }
</style>';

Code (2.1 series) Select
addInlineCss('
textarea#mwll_code { width: 90%; }');


I will add to my mod in next update. :D

Advertisement: