CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Multi-select box size.
Pages: [1]

Author Topic: Multi-select box size.  (Read 6045 times)

Chris7789

  • Guest
Multi-select box size.
February 19, 2009, 02:01:25 am
Could someone point me in the right direction for changing the default sizes of a Multi-select box?

I see that have a set height and a fluid width. I would really like to be able to set the height and width for all multi-select boxes.

Any help would be greatly appreciated.

Thanks

Chris

Yashodha Chaku

  • Forum Godess / God
  • Ask me questions
  • *****
  • Posts: 755
  • Karma: 57
    • CiviCRM
Re: Multi-select box size.
February 19, 2009, 02:25:33 am
Chris:

Quote
Could someone point me in the right direction for changing the default sizes of a Multi-select box?

Can you check CRM/Core/BAO/CustomField.php for case 'Multi-Select' around Line no:637,
you can set the size attribute for the multi-select field here:

Code: [Select]
$qf->addElement('select', $elementName, $label, $selectOption,  array("size"=>"5","multiple"));
HTH
-Yashodha

Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

Chris7789

  • Guest
Re: Multi-select box size.
February 19, 2009, 03:11:11 am
Thanks Yashodha,

That has worked for the height, not sure what I need to change to give them all a set width.

Any ideas?

Thanks

Chris
« Last Edit: February 19, 2009, 10:50:32 am by Chris7789 »

Chris7789

  • Guest
Re: Multi-select box size.
February 22, 2009, 12:22:01 pm
Can anyone tell me what I need to change/add to make the boxes a set width?

Thankyou

Chris

Code: [Select]
        case 'Multi-Select':
            $selectOption =& CRM_Core_OptionGroup::valuesByID( $field->option_group_id );
            $qf->addElement('select', $elementName, $label, $selectOption,  array("size"=>"3","multiple"));
           
            if (( $useRequired ||( $useRequired && $field->is_required) ) && !$search) {
                $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)) , 'required');
            }
            break;[

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Multi-select box size.
February 22, 2009, 10:43:27 pm
You can specify style for multi-select.
Quote
$qf->addElement('select', $elementName, $label, $selectOption,  array("size"=>"5","multiple", style =>"width:150px"));

HTh

Kurund
Found this reply helpful? Support CiviCRM

Chris7789

  • Guest
Re: Multi-select box size.
February 23, 2009, 06:40:16 am
Thankyou, that worked a treat.

Chris7789

  • Guest
Re: Multi-select box size.
February 26, 2010, 05:24:39 am
Can you specify the style for a 'Select' box to change the width? I tried but failed.

Code: [Select]
case 'Select':
            $selectOption =& CRM_Core_OptionGroup::valuesByID( $field->option_group_id );
            $qf->add('select', $elementName, $label,
                     array('' => ts('- select -')) + $selectOption,
                     ( ( $useRequired || ($useRequired && $field->is_required) ) && !$search));
« Last Edit: February 26, 2010, 05:26:15 am by Chris7789 »

Kiran Jagtap

  • Ask me questions
  • ****
  • Posts: 533
  • Karma: 51
Re: Multi-select box size.
February 26, 2010, 05:50:32 am
you can specify your attributes as sixth argument to add function like

Code: [Select]
case 'Select':
            $selectOption =& CRM_Core_OptionGroup::valuesByID( $field->option_group_id );
            $qf->add( 'select', $elementName, $label,
                     array('' => ts('- select -')) + $selectOption,
                     ( ( $useRequired || ($useRequired && $field->is_required) ) && !$search),
                     array("size"=>"5","multiple", style =>"width:150px") );

hope this help

kiran
« Last Edit: February 26, 2010, 05:52:09 am by Kiran Jagtap »
You Are Designed To Choose... Defined By Choice.

Chris7789

  • Guest
Re: Multi-select box size.
March 01, 2010, 05:17:44 am
Thank you. Has worked.

Chris7789

  • Guest
Re: Multi-select box size.
March 02, 2010, 12:07:29 pm
Sorry to be a pain. Now seem to be having same problem with 'text'.

Code: [Select]
case 'Text':
            if ($field->is_search_range && $search) {
                $qf->add('text', $elementName.'_from', $label . ' ' . ts('From'), $field->attributes);
                $qf->add('text', $elementName.'_to', ts('To'), $field->attributes);
            } else {
                $element =& $qf->add(strtolower($field->html_type), $elementName, $label,
                                     $field->attributes, (( $useRequired ||( $useRequired && $field->is_required) ) && !$search));
            }
            break;

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Multi-select box size.
March 02, 2010, 05:09:09 pm
If these are global changes, you might want to experiment with making your modifications via CSS. You can add styles to civicrm/css/extras.css - which will be loaded on all civicrm/ path pages. You might need to use the !important declaration to force your additional style to over-ride other declared size styles. However, if this works - it's much better than modifying / customizing core code files.
Protect your investment in CiviCRM by  becoming a Member!

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Multi-select box size.
October 13, 2010, 05:52:24 pm
I thought I would just touch base on this subject.

Making the width change via a stylesheet is the preferred method however because the width is specifically set in CRM/Core/BAO/CustomField.php you cannot override the elements width value. In the version I am using 3.2.1 the width is specifically set to 150px on line 691. I commented out the 150px and changed it to 220 however I suppose it would be just as easy to comment out line 691 and then adjust it via the stylesheet by applying a width to the class advmultiselect.

Code: [Select]
            case 'AdvMulti-Select':
            $selectOption =& CRM_Core_BAO_CustomOption::valuesByID( $field->id,
                                                                    $field->option_group_id );
            $include =& $qf->addElement('advmultiselect', $elementName,
                                        $label, $selectOption,
                                        array('size' => 5,
                                              //'style' => 'width:150px',
                                              'style' => 'width:220px',
                                              'class' => 'advmultiselect')
                                        );
           
            $include->setButtonAttributes('add', array('value' => ts('Add >>')));
            $include->setButtonAttributes('remove', array('value' => ts('<< Remove')));     
           
            if (( $useRequired ||( $useRequired && $field->is_required) ) && !$search) {
                $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)) , 'required');
            } 
            break;

My CiviCRM Extension Workshop: https://github.com/awasson

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Multi-select box size.
November 03, 2010, 04:51:41 pm
Makes sense to move this style to civicrm.css. Took a bit of snooping - had to leave style attribute in array empty to prevent QuickForm from applying width: 100px. Changes committed to 3.3 branch:

http://issues.civicrm.org/jira/browse/CRM-7030
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Multi-select box size.

This forum was archived on 2017-11-26.