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) »
  • Hide or show fields
Pages: [1]

Author Topic: Hide or show fields  (Read 541 times)

Rudy Madsen

  • I post occasionally
  • **
  • Posts: 68
  • Karma: -2
  • CiviCRM version: 4.4.6
  • CMS version: Joomla 2.5 > 3.3
Hide or show fields
August 27, 2014, 02:15:07 am
How can I show or hide custom made fields which are dependent on another field's choice.
Regards

Rudy Madsen

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Hide or show fields
August 27, 2014, 02:49:43 am
You would need to use jQuery to do that.
Try asking your question on the new CiviCRM help site.

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Hide or show fields
August 27, 2014, 03:42:03 am
What Coleman said, but with a bit more background:

Conditional custom fields are not available with out of the box CiviCRM, but if you are comfortable with some simle programing, you could use jQuery to acheive what you want.
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

smksites

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 4.3.7
  • CMS version: Drupal
  • MySQL version: 5.5
  • PHP version: 5.4
Re: Hide or show fields
March 07, 2015, 02:48:32 pm
Drupal civicrm 4.3.7

In this example the custom field is 55.  If the value of custom_55 is "189" it shows the field custom_8.  If not custom_8 is hidden.
If this was on the contact form you would add the code to templates/crm/contact/form/edit/CustomData.tpl and templates/crm/contact/form/inline/CustomData.tpl

 
Code: [Select]
<script type="text/javascript">
    {literal}

cj("[name^=custom_55_]").on('change', function() {
 
  if(this.value == 189)
  {
 cj("[class^='custom_field-help-pre-row custom_8_']").css("display", "table-row");
  cj("[class^='custom_field-row custom_8_']").css("display", "table-row");
 
}
else
{
  cj("[class^='custom_field-help-pre-row custom_8_']").css("display", "none");
   cj("[class^='custom_field-row custom_8_']").css("display", "none");

}
});
var custom;

custom = cj("[name^=custom_55_]").val();
if(custom != 189)
{
cj("[class^='custom_field-help-pre-row custom_8_']").css("display", "none");
  cj("[class^='custom_field-row custom_8_']").css("display", "none");

}
{/literal}
  </script>
« Last Edit: March 22, 2015, 02:34:39 pm by smksites »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Hide or show fields

This forum was archived on 2017-11-26.