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 (Moderator: Dave Greenberg) »
  • Custom Fields dropdowns linked by AJAX?
Pages: [1]

Author Topic: Custom Fields dropdowns linked by AJAX?  (Read 1573 times)

Luciano S.

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
  • iXiam Team Leader
  • CiviCRM version: 4.2+ / 4.3+ / 4.4+
  • CMS version: Drupal
  • MySQL version: 5.1+ / 5.5+
  • PHP version: 5.3+ / 5.4+
Custom Fields dropdowns linked by AJAX?
January 28, 2011, 02:41:29 am
Hi guys,

I'm pretty new with CiviCRM and I wanted to know if there is any way (or workaround) to link some custom fields (selection style) in cascade, filtering the options by AJAX.

It would have the same behaviour as Country ->  State/Province in the address tab.. Selecting the country filters the State's options.
So I need to do the same but with custom fields, and there will be like 4 or 5 dropdowns linked in cascade

Thanks in advance!!

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Custom Fields dropdowns linked by AJAX?
January 28, 2011, 02:56:16 am
Hi,

Read the chapter in the book about development and extending, should get you started.

In your case, it seems that doing a custom template and using the rest interface API if you need to link the ajax to content in the DB (list of contacts, groups...).

And jquery is your friend, they are various examples in the blog about how to add code in the templates.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Luciano S.

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
  • iXiam Team Leader
  • CiviCRM version: 4.2+ / 4.3+ / 4.4+
  • CMS version: Drupal
  • MySQL version: 5.1+ / 5.5+
  • PHP version: 5.3+ / 5.4+
Re: Custom Fields dropdowns linked by AJAX?
January 28, 2011, 04:00:04 am
Tx Xavier for your answer,

so the best approach it's to create a custom template for this?
I'm little worried cause the intention it's that these fields will be used in the New Individual Contact form (in the Address tab) so if I modified this template and eventually I upgrade the civiCRM version I have to be very careful to not lose these changes and verify that are compatible with the future versions.. of course using the API might guaranty the compatibility I guess..

I will research more in detail, any suggestion if someone had the same scenario will be more than welcome.

luc

Luciano S.

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
  • iXiam Team Leader
  • CiviCRM version: 4.2+ / 4.3+ / 4.4+
  • CMS version: Drupal
  • MySQL version: 5.1+ / 5.5+
  • PHP version: 5.3+ / 5.4+
Re: Custom Fields dropdowns linked by AJAX?
January 28, 2011, 04:17:24 am
To be more specific what I need is to have in any New Individual Contact form (in the main form and in the custom profile forms that are created) in the address tab 5 dropdowns linked in cascade:

Country  -->  State/Province  -->  County  -->  City  -->  ZIP code

So first you select the Country, it filters the State's options, then selecting the State filters the County and etc..
The system works so far only with Country --> State relationship, the County field exists but is't not related with province (I saw in a post that it's planned for future releases) but after County i have 2 more custom fields to add and be AJAX-filtered.

so I'm trying to figure out how is the best approach for this customization.

I hope it's clear now the idea.

Tx.
luc


Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Custom Fields dropdowns linked by AJAX?
January 28, 2011, 05:55:20 am
If the fields exist on the page already, you don't need to customize the template actually. All of your functionality can be achieved purely via jQuery, on the client side. If the fields aren't there, I think you could just make them using the regular CiviCRM interface for creating custom fields.

You just need to add the required handlers to the various select objects, and then write the server side code to send the new content for each. This you would do in a custom Drupal module you would write.

The other issue would be the location of the fields, as custom fields won't go next to the default State dropdown. However, moving the field on the page can also be done via jQuery. Or you could hide the 'real' field and add a "fake" field via jQuery and then onsubmit, just transfer the value from fake to real so it's submitted to the backend.

Or you could customize templates as noted, but I would think a jQuery approach would be worth the higher initial investment, because then upgrades should be easier to handle.
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.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Custom Fields dropdowns linked by AJAX?
January 28, 2011, 07:29:33 am
Hi hershel,

how do you manage to inject the jquery in the form without doing a custom template ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Custom Fields dropdowns linked by AJAX?
January 29, 2011, 12:09:31 pm
Quote from: xavier on January 28, 2011, 07:29:33 am

how do you manage to inject the jquery in the form without doing a custom template ?

Hi. jQuery can be added either via a customized Drupal theme or via a custom Drupal module.
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.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Custom Fields dropdowns linked by AJAX?

This forum was archived on 2017-11-26.