How to Control Form Field Widths in Edit View (NOT Detail View)

In detail view, I can easily add columns and adjust the label and field widths by editing the detailviewdefs.php in various modules. However, changes the column parameters in editviewdefs.php does not have the same effect as the form field widths never change! I’ve tried quick repair too.

Specifically, my custom/modules/Accounts/metadata/editviewdefs.php has this in it. The changes to the number of columns works but the field widths don’t change (changed from 30 to 15.) It seems to me what is happening is because there are form fields (mostly text input boxes) the width of the text input boxes needs to be changed as the table is just expanding to widths to accomodate those text input box widths regardless of the settings below. How can I control the default text input field width for a given modeule edit view?

‘maxColumns’ => ‘6’,
‘widths’ =>
array (
0 =>
array (
‘label’ => ‘10’,
‘field’ => ‘15’,
),
1 =>
array (
‘label’ => ‘10’,
‘field’ => ‘15’,
),
2 =>
array (
‘label’ => ‘10’,
‘field’ => ‘15’,
),
3 =>
array (
‘label’ => ‘10’,
‘field’ => ‘15’,
),
4 =>
array (
‘label’ => ‘10’,
‘field’ => ‘15’,
),
5 =>
array (
‘label’ => ‘10’,
‘field’ => ‘15’,
),
),

If I look at the HTML source, the size setting for most of the text inputs is 30. It seems to me what is happening is although you can edit the table (TD) width via the viewdef, SugarCRM still defaults the input text boxes to a size 30 (the default column width size of the table). Ideally, I think it would be best to set the text input size to the same as the maxlength, this way you can easily control the text input width via the field maxlength definition via Studio instead of having to implement custom CSS.

Barring something I’ve overlooked already in Sugar to control the input text fields width in a module edit view, I suppose I just need to find the point in the PHP display code that sets the input field size attribute and modify it to use the maxlength value.

Think I found it. It’s in SugarFields/Base/EditView.tpl but I’m too rusty on my Smarty to whip out the code.

<input type=‘text’ name=’{{if empty($displayParams.idName)}}{{sugarvar key=‘name’}}{{else}}{{$displayParams.idName}}{{/if}}’
id=’{{if empty($displayParams.idName)}}{{sugarvar key=‘name’}}{{else}}{{$displayParams.idName}}{{/if}}’ size=’{{$displayParams.size|default:30}}’
{{if isset($displayParams.maxlength)}}maxlength=’{{$displayParams.maxlength}}’{{elseif isset($vardef.len)}}maxlength=’{{$vardef.len}}’{{/if}}
value=’{$value}’ title=’{{$vardef.help}}’ {{if !empty($tabindex)}} tabindex=’{{$tabindex}}’ {{/if}}
{{if !empty($displayParams.accesskey)}} accesskey=’{{$displayParams.accesskey}}’ {{/if}} {{$displayParams.field}}>

Basically I want, IF $vardef.len < 30 (the default) then size=’{{$vardef.len}}’ This prevents if the default maxlength is 255 (or anything greater than 30) then it won’t make the fields larger than the default 30 width.

I still think it would be cleaner if there was a way to control the $displayParams.size value via the custom field settings.

Should be able to figure out the smarty… but if someone wants to throw me a bone.

I found a solution online but it’s not working on my side for some reason

You would edit the metadata file and add something like the following to your field

‘displayParams’=>array(‘size’=>100),

1 Like

I found a way to do this by modifying a .tpl file

Here’s the video that explains it

https://www.youtube.com/watch?v=SNC1V6g2gVk&feature=youtu.be

Here’s a link to the file in the video:
http://wiki-crm-forum.com/forum/viewtopic.php?f=2&t=9641&sid=c315fc46a108285f381a84187b3a6846

Wow… Thank you was searching for it…

1 Like