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) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions »
  • CiviContribute Suggestions »
  • Contribution type selection with one value
Pages: [1]

Author Topic: Contribution type selection with one value  (Read 3165 times)

khapeman

  • Guest
Contribution type selection with one value
December 14, 2009, 08:50:09 am
It would be helpful to eliminate the -select- option when there is only one value to be selected.  We have only 1 contribution type and every entry of a new contribution requires extra mouse clicks just to choose the only value available.  If the -select- were removed and only "Donation" showed in the box, no clicks would be involved.  Any thoughts on a way around this would be appreciated!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Contribution type selection with one value
December 14, 2009, 01:07:21 pm

yes, i think we should fix the framework to do the foll:

if there is only one option in a select/checkbox/radio/etc and that option is required, display the selected value and freeze the field

however if that option is not required, then we should not do the above (since it could be null)

the easiest workaround for now is to implement this via the hook_civicrm_buildForm for that form and set the default value (and u can also freeze the field if needed). hooks are documented here:

http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

khapeman

  • Guest
Re: Contribution type selection with one value
December 15, 2009, 07:01:28 am
Thanks - that's a good workaround, but I'm having some trouble figuring out how to implement it.  I get this from the actual form itself (view source):

<form  action="/drupal/index.php?q=civicrm/contribute/add" method="post" name="Contribution" id="Contribution" enctype="multipart/form-data" >

and the specific data element:

<select onchange="buildCustomData( 'Contribution', this.value );" name="contribution_type_id" id="contribution_type_id" class="form-select required">
   <option value="">- select -</option>
   <option value="1">Donation</option>
</select>

Looking for an example, I found this code that you supplied in response to another question:
   if ($formName == "CRM_Contact_Form_Contact" &&
            $form->elementExists( 'external_identifier' ) ) {
      $elem = $form->getElement('external_identifier');
      $elem->freeze();
   }

So it looks to me like my form name is just "Contribution" and the element is "contribution_type_id".  Am I on the right track?  Now I need to be able to test if there is only one value for the select - not sure how to do that.  Any other suggestions would be appreciated!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Contribution type selection with one value
December 15, 2009, 08:32:45 am

1. take a look at the code in this module:

http://svn.civicrm.org/sfschool/trunk/drupal/sfschool/sfschool.module

it implements quite a few hooks and will give u a flavor of the various parameters

2. also check the hook documentation and the civitest.module.sample module shipped with each distribution

3. for the select element stuff, i would add some debug statements and see what info i can get from quickform to detect if one element etc. QF documentation is here: http://pear.php.net/manual/en/package.html.html-quickform.php

u need to be a pretty good PHP developer for the above, IMO.

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

khapeman

  • Guest
Re: Contribution type selection with one value
December 15, 2009, 03:30:58 pm
Thanks, lobo!  One more thought on elements like contribution_type - if you could specify a default value like you can for custom fields, that would make the default value show as the top choice in the select box even if there is only 1 value and no mouse clicks would be required to make that selection.  This could also be handy even if there were multiple values if most of the contributions to an organization were of 1 type.

khapeman

  • Guest
Re: Contribution type selection with one value
December 15, 2009, 07:10:23 pm
This code seems to work for us.  It sets the value to 1 which is our contribution_type_id for "Donation".  The select box now displays "Donation" at the top of the select box on the New Contribution form instead of "-select-".  The only thing that doesn't happen is the custom group of fields that are tied to the contribution type of "Donation" doesn't open up unless you select the box manually, but we have already changed that on our production system to open for "Any" new contribution, so it's not an issue for us.  Here's the code:

function spc_civicrm_buildForm( $formName, &$form ) {
   if ($formName == "CRM_Contribute_Form_Contribution" &&
            $form->elementExists( 'contribution_type_id' ) ) {
      $form->getElement('contribution_type_id')->setValue(1);
   }
}

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions »
  • CiviContribute Suggestions »
  • Contribution type selection with one value

This forum was archived on 2017-11-26.