1

Stuck with jQuery, which intercepts a contact Quick Edit and updates a custom field. All is fine and a value gets updated in the database but is not immediately shown, need to click "Edit" again to see it changed. Have been searching high and low here https://docs.civicrm.org/dev/en/latest/framework/ajax/#crmrefreshparent and in the code for "refreshParent" to no avail. Any pointer in the right direction please?

CRM.$(function ($) {
$(document).on('crmFormSuccess', function (e, data) {
    var changedElement = $(this);
    console.log(changedElement);
    if (typeof (data) == 'object') {
        // data.status: success|| form_error
        if (data.status === 'success') {
            const userContext = data.userContext.split('=');
            const cid = userContext[userContext.length - 1];
            CRM.api3('Contact', 'get', {
                "return": ["custom_1", "custom_2"],
                "id": cid
            }).then(function (result) {
                    CRM.api3('CustomValue', 'create', {
                        "entity_id": result.id,
                        "custom_2": result.values[result.id].custom_1 == "1"?   "1" : "0"
                    }).then(function (result) {
                       // Please, refreshParent, if you can! 
                        }, function (error) {
                        // oops
                    });
            }, function (error) {
                // oops
            });
        }
    }
 });
});

1 Answer 1

2

Use below

$('.crm-custom-set-block-5 .crm-summary-block').load(CRM.url('civicrm/ajax/inline', {
  cid: '133', 
  class_name: 'CRM_Contact_Page_Inline_CustomData', 
  groupID: '5', 
  customRecId: '1', 
  cgcount: '1',
  reset: 1,
  snippet: 5,
  type: 'page'
}), function() {
  $(this).trigger('crmLoad');
});

replace

  1. cid to contact_id
  2. groupId with custom group Id
  3. .crm-custom-set-block-5, replace 5 with custom group id
7
  • in my case it is 'form.CRM_Contact_Form_Inline_CustomData' and unfortunately it is not being triggered.
    – yurg
    Commented Nov 22, 2023 at 13:55
  • does the custom set is on Summary tab or on its own tab? Commented Nov 22, 2023 at 14:22
  • is on Summary tab and its equivalent of $el would be e.target.childNodes[3] (which is a div with "crm-container-snippet") class - assuming the result of .crmSnippet(); on the element.
    – yurg
    Commented Nov 22, 2023 at 14:32
  • I have updated my answer Commented Nov 22, 2023 at 16:13
  • I'd say this sends the investigation into the whole new direction. It works! Would you please point me to documentation regarding the solution and data-edit-params usage ( if exists )? Cheers.
    – yurg
    Commented Nov 23, 2023 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.