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

Author Topic: Conditional fields  (Read 4829 times)

EdP

  • I post frequently
  • ***
  • Posts: 260
  • Karma: 7
  • CiviCRM version: 4.4
  • CMS version: Joomla 2.5.x
Conditional fields
January 18, 2010, 06:55:16 am
I know how to make a field mandatory, or not mandatory in a profile (e.g. for membership sign up).

Is it possible to make a field mandatory if some other field has been ticked? So, for example, is it possible to make a date of birth field mandatory if someone has declared they're under 18, or if they've selected a membership rate for the over 65s? Could I require that someone who has ticked the "I'd like to Gift Aid this money" [a UK tax thing, where a charity can get a money back if money donated by a UK tax payer] has to fill out name and address, but those who haven't don't?


Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Conditional fields
January 18, 2010, 12:22:48 pm
You'll need to customize the edit form template for that profile and add javascript logic to enforce the conditional requirements / conditional field display.
Protect your investment in CiviCRM by  becoming a Member!

Yoda_Oz

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 3.3.3
  • CMS version: Joomla 1.5.22
Re: Conditional fields
June 20, 2010, 05:43:29 pm
im interested in this..

can someone please help me get started with the javascript code needed and which files to edit? i want a mandatory tickbox to show if someone chooses a particular membership option.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Conditional fields
June 21, 2010, 02:48:20 am
This could be done purely with jQuery--I don't see any reason to edit any template files. You would simply need to add a jQuery file to your page (in the theme or via a module for Drupal).

> can someone please help me get started with the javascript code needed

http://docs.jquery.com/
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Yoda_Oz

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 3.3.3
  • CMS version: Joomla 1.5.22
Re: Conditional fields
June 21, 2010, 03:27:06 am
im using joomla... can this be done in joomla too?

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Conditional fields
June 21, 2010, 03:33:15 am
Yes. I don't know the correct way to add a JS file in Joomla, but you certainly *could* just add the reference to it in the main Joomla template.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Conditional fields
May 30, 2012, 02:29:49 pm
just wondering if anyone ended up making this work via jquery and if so, if you'd be willing to share the code :)

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Conditional fields
May 30, 2012, 03:42:08 pm
Hi Emily!
Not sure if anyway has done this (probably but didn't share). In current versions you can use this feature to much more easily add jQuery snippets for a specific form:

http://civicrm.org/blogs/dave-greenberg/now-its-easier-add-custom-behaviors-templates

There's examples of jQuery snippets which show, hide, change values, freeze etc. all over the templates folders. check this one for some potentially useful examples:

templates/CRM/Contribute/Form/ContributionPage/Amount.tpl
Protect your investment in CiviCRM by  becoming a Member!

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Conditional fields
May 30, 2012, 06:51:54 pm
Awesome, Dave, thanks!

I'll check into it and see what I can come up with, and I will post docs on anything I do :)

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

This forum was archived on 2017-11-26.