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 CiviEvent (Moderator: Yashodha Chaku) »
  • Have custom profile show/hide dynamically
Pages: [1]

Author Topic: Have custom profile show/hide dynamically  (Read 1083 times)

RachelWright

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 3
  • CiviCRM version: 4.2.7
  • CMS version: Joomla 2.5.17
  • MySQL version: 5.5.37
  • PHP version: 5.4.26
Have custom profile show/hide dynamically
March 21, 2013, 12:11:56 pm
Is there a way to add a class name to a custom profile (to the fieldset)? So that I could easily hide it based on a price set selection? I can successfully hide one field in a profile, but I'd like to hide the whole custom profiel at once. Suggestions?

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Have custom profile show/hide dynamically
March 21, 2013, 02:40:59 pm
Hi Rachel - I think the only way to do it right now is to use some xPath selector to allow jQuery to find the Nth fieldset. However you've raised a really valid use case - the profile fieldset elements should include an identifying class.

I'd like to improve this in 4.3 - by changing this line in templates/CRM/UF/Form/Block.tpl:
Code: [Select]
            <fieldset><legend>{$field.groupTitle}</legend>

... to this:
Code: [Select]
        <fieldset class="{$field.groupTitle|replace:' ':'_'|escape:javascript}"><legend>{$field.groupTitle}</legend>

This will put an escaped string derived from the profile title as the fieldset class.

Want to try that in your site and see if it helps you?


Protect your investment in CiviCRM by  becoming a Member!

RachelWright

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 3
  • CiviCRM version: 4.2.7
  • CMS version: Joomla 2.5.17
  • MySQL version: 5.5.37
  • PHP version: 5.4.26
Re: Have custom profile show/hide dynamically
March 21, 2013, 02:47:42 pm
Worked great, the class is now the name of the name of the group!! I can target it without writing code to figure out which set it is on the page!!!

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Have custom profile show/hide dynamically
March 22, 2013, 12:48:46 pm
Rachel - after further discussion, determined that using the ID of the profile is safer and probably more stable.
In 4.3 the markup will be:
Code: [Select]
<fieldset class="crm-profile crm-profile-id-{$field.group_id"><legend>{$field.groupTitle}</legend>

You can find the ID from Administer > Customize Data & Screens > Profiles (3rd column in listing).

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

RachelWright

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 3
  • CiviCRM version: 4.2.7
  • CMS version: Joomla 2.5.17
  • MySQL version: 5.5.37
  • PHP version: 5.4.26
Re: Have custom profile show/hide dynamically
March 29, 2013, 08:54:53 am
Great thanks!

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Have custom profile show/hide dynamically
March 31, 2013, 04:14:32 pm
Rachel - after FURTHER discussion, I also added the profile 'name' class. This is a sanitized version of the profile title and s/b stable across copies of a site so might be better than profile id. More info on the issue tracker.
Protect your investment in CiviCRM by  becoming a Member!

RachelWright

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 3
  • CiviCRM version: 4.2.7
  • CMS version: Joomla 2.5.17
  • MySQL version: 5.5.37
  • PHP version: 5.4.26
Re: Have custom profile show/hide dynamically
April 11, 2013, 11:05:16 am
you guys are awesome!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Have custom profile show/hide dynamically

This forum was archived on 2017-11-26.