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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • EntityRef - Dynamically update parameters?
Pages: [1]

Author Topic: EntityRef - Dynamically update parameters?  (Read 411 times)

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
EntityRef - Dynamically update parameters?
October 08, 2014, 12:13:53 pm
I have 2 entityRefs on the same page. I have the user select a value from one entityRef. I want to get the resulting ID from that selection and feed it into the following entityRef with the "thisDC" variable. The problem is that that value seems to be static and does not read the new value that I set on the variable. Is there any way to do this?

$('[name=field_selectSG]').crmEntityRef({
        entity: 'group',
      api: {
          params: {
              //contact_type: 'Individual',
              parents: thisDC // dc id
          }},
      create: false   
    });

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: EntityRef - Dynamically update parameters?
October 08, 2014, 12:41:54 pm
I'm surprised that code doesn't work.
But here's how we do it in the relationship form (dynamically switching available contact types based on chosen relationship type):
https://github.com/civicrm/civicrm-core/blob/master/templates/CRM/Contact/Form/Relationship.tpl#L182
Note setting data('api-params') and you might want to take a cue from there and also clear the value and trigger change since the user might have previously selected a now-illegal value.
Try asking your question on the new CiviCRM help site.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: EntityRef - Dynamically update parameters?
October 08, 2014, 12:45:53 pm
One more suggestion - I don't know if you noticed our "events" entityRef fields (check it out on the "Register Event Participant" form) we set the 'minimumInputLength' to 0 which causes it to open immediately instead of waiting for search input. This might be a nice touch for your groups selector too.
Try asking your question on the new CiviCRM help site.

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Re: EntityRef - Dynamically update parameters?
October 09, 2014, 07:42:13 am
Excellent. I'll look into how you do it in the relationship form. I think I see what you are doing there.

I was just thinking about how nice it would be to have the entityRef show the list without having to type anything. Thanks for that foresight! :)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • EntityRef - Dynamically update parameters?

This forum was archived on 2017-11-26.