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) »
  • refresh read only custom field value after another custom field has changed
Pages: [1]

Author Topic: refresh read only custom field value after another custom field has changed  (Read 972 times)

questions

  • I post occasionally
  • **
  • Posts: 79
  • Karma: 2
  • CiviCRM version: 4.4.6
  • CMS version: Durpal, 7
  • MySQL version: 5.1
  • PHP version: 5.3
refresh read only custom field value after another custom field has changed
February 20, 2015, 06:47:42 pm
I have several custom fields on the contact form.  One is a read only field based upon another field.  A db trigger updates the read only field in the database. 

How do I get the value of the read only field updated in the form after the user changes the other custom field?  I'm pretty sure a postprocess hook is the way to trigger the refresh, but what is the recommended way to requery the read only field.  Altercontent seems like it might work but maybe a bit too brute force.

Forgive me if this has been asked and answered before or is in the docs.  I didn't find it.

norris

  • I’m new here
  • *
  • Posts: 19
  • Karma: 0
  • CiviCRM version: 4.6.0
  • CMS version: Joomla
  • MySQL version: 5.5.41-37.0-log
  • PHP version: 5.4.24
Re: refresh read only custom field value after another custom field has changed
March 15, 2015, 07:38:08 pm
Did you find any solution to this, questions?  I'm trying to figure out the same thing!

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: refresh read only custom field value after another custom field has changed
March 15, 2015, 08:07:22 pm
You might also want to consider the jQuery approach - particularly if the first field is edited via inline editing, and the second field isn't in the same inline region (if it is, I assume this is a non-issue?).  But I'm not sure you mean inline editing, because then I'm not sure how you'd be calling alterContent or postProcess.

Could you say more about how the user edits the writable field, and whether the read-only field is in the same inline region, if you're using inline editing?
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

norris

  • I’m new here
  • *
  • Posts: 19
  • Karma: 0
  • CiviCRM version: 4.6.0
  • CMS version: Joomla
  • MySQL version: 5.5.41-37.0-log
  • PHP version: 5.4.24
Re: refresh read only custom field value after another custom field has changed
March 15, 2015, 08:19:33 pm
For my organization, members maintain membership by either submitting a quarterly plan of activity they're doing, or by donating a minimum amount each quarter.  I created a set of custom fields to hold these quarterly plans, and used pre and post hooks to check for changes to Donation Contributions or to Memberships.  If a donation is made and the person is currently a member, the donation is added to a read-only field that tallies all the contributions for that quarter.

I think I have all the hook logic working.  The custom fields are in a tab of their own.  After entering a donation, clicking over to that tab doesn't show the new value of the read-only field.  I have to refresh the contact profile to see the change.

Not a huge problem, but it'd be nice to automatically refresh that tab or those fields when membership info is changed or donations are entered or changed.

questions

  • I post occasionally
  • **
  • Posts: 79
  • Karma: 2
  • CiviCRM version: 4.4.6
  • CMS version: Durpal, 7
  • MySQL version: 5.1
  • PHP version: 5.3
Re: refresh read only custom field value after another custom field has changed
March 27, 2015, 02:38:06 pm
Sorry for not replying sooner.  Got sidetracked with other issues.

The editing is inline and as you guessed the other field is in a different inline region.

So what is the jQuery approach?

I too would like to update tab values as well, like norris wants.

I figure there must be some standard call do both of these, but knowing the command and the syntax, well that's the rub.

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: refresh read only custom field value after another custom field has changed
March 27, 2015, 02:39:44 pm
I think what you all are looking for is CRM.refreshParent?

http://wiki.civicrm.org/confluence/display/CRMDOC/Ajax+Pages+and+Forms#AjaxPagesandForms-CRM.refreshParent

If not, check that whole page to see if it's helpful - and please report back if you find an answer!
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

questions

  • I post occasionally
  • **
  • Posts: 79
  • Karma: 2
  • CiviCRM version: 4.4.6
  • CMS version: Durpal, 7
  • MySQL version: 5.1
  • PHP version: 5.3
Re: refresh read only custom field value after another custom field has changed
March 27, 2015, 03:52:51 pm
I had tried the CRM.refreshParent before but thought I'd try it again.  I put it in a post processing hook.  For test, pretty basic

function ccas_hooks_civicrm_postProcess($formName, &$form)
{
//don't do just this in prod, add if correct form name, etc.
CRM.refreshParent;
}

It doesn't work but then I suspect I don't have something right.  I get these errors in the log

Notice: Use of undefined constant refreshParent - assumed 'refreshParent'
Notice: Use of undefined constant CRM - assumed 'CRM'

It looks like it doesn't know about CRM. 

I looked through the page you suggested as I have a number of times over the past weeks and looked for examples in the code tree but didn't find anything that jumps out at me.

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: refresh read only custom field value after another custom field has changed
March 27, 2015, 04:59:55 pm
Hmm.  Are you in the CiviCRM Stack Exchange private beta?  If not, PM me your e-mail address and I'll send you an invite (or just wait until it's public on Tuesday).

Right now, since we have to establish a certain level of quality/activity, there are some extremely knowledgeable folks who will answer any question that they can.  I posted two questions yesterday that I wouldn't normally expect to see an answer about on here!  I bet if you reposted this there, you'd see some results.
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • refresh read only custom field value after another custom field has changed

This forum was archived on 2017-11-26.