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 (Moderator: Donald Lobo) »
  • Inline editing of custom data
Pages: [1]

Author Topic: Inline editing of custom data  (Read 501 times)

JohnFF

  • I post frequently
  • ***
  • Posts: 235
  • Karma: 6
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.28
  • MySQL version: 5.5.31-1
  • PHP version: 5.3.27
Inline editing of custom data
August 05, 2014, 12:02:27 pm
There's a really good UK Phone Number Validator extension* that uses inline editing to help users clean up their phone numbers.

The question is, how can I do the same for custom data sets?

Do I need to add to the api to make inline editing work?
Either way, what would I need to set the below to?

For a phone number it's (abridged):

Code: [Select]
<tr id="phone-{$eachRecord.phone_id}" class="crm-entity {$eachRecord.phone_id}">
<td>
<span id="phone-{$eachRecord.phone_id}" class="crmf-phone crm-editable">{$eachRecord.phone}</span>
</td>
</tr>

This includes:
1) Custom data off a contact.
2) Custom data off a relationship.

Thanks all!



*So I hear :P
If you like empowering charities in a free and open way, then you're going to love Civi.

Email Amender: https://civicrm.org/extensions/email-amender
UK Phone Validator: https://civicrm.org/extensions/uk-phone-number-validator
http://civifirst.com
https://twitter.com/civifirst

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Inline editing of custom data
August 07, 2014, 08:19:20 am
As long as the markup includes the entity type, entity id, and name of the field, it should work like magic. Since your table row will include a mix of entities, I suggest you add a <div> inside each cell that has the field name, and have each <td> get the entity name and id. Use data rather than id since you can't have duplicate ids in the dom (or shouldn't)
Try asking your question on the new CiviCRM help site.

JohnFF

  • I post frequently
  • ***
  • Posts: 235
  • Karma: 6
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.28
  • MySQL version: 5.5.31-1
  • PHP version: 5.3.27
Re: Inline editing of custom data
August 12, 2014, 07:37:11 am
Thanks for responding Coleman. Sadly, I'm not quite there yet :(

When I have the following (abridged):

Code: [Select]
<span id="contact-8557" class="crm-entity 8557">
            <span id="contact-8557" class="crmf-custom_35 crm-editable">test maiden name</span>
</span>

The database is like this:
mysql> describe civicrm_value_additional_contact_details_12;
+------------------+------------------+------+-----+---------+----------------+
| Field            | Type             | Null | Key | Default | Extra          |
+------------------+------------------+------+-----+---------+----------------+
| id               | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| entity_id        | int(10) unsigned | NO   | UNI | NULL    |                |
| previous_name_35 | varchar(255)     | YES  |     | NULL    |                |
+------------------+------------------+------+-----+---------+----------------+


I edit the inline message and get the error message "DB error: no such field".

However, when I do a print out of the column names available to the generic setvalue api function custom_35 appears there, and I don't get the standard error Param 'field'  is invalid. must be an existing field

Looking in the log shows: DB_mysql->simpleQuery("SELECT  id, custom_35  \n FROM civicrm_contact \n \n WHERE (  civicrm_contact...")

Obviously, as custom_35 is custom data it isn't in the civicrm_contact table.

What should my data be?
If you like empowering charities in a free and open way, then you're going to love Civi.

Email Amender: https://civicrm.org/extensions/email-amender
UK Phone Validator: https://civicrm.org/extensions/uk-phone-number-validator
http://civifirst.com
https://twitter.com/civifirst

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Inline editing of custom data
August 12, 2014, 10:24:04 am
This is another case where you will need to use the "create" action instead of "setvalue".
"setvalue" is just a really dumb function that writes a single field to a single table, nothing more.
Try asking your question on the new CiviCRM help site.

JohnFF

  • I post frequently
  • ***
  • Posts: 235
  • Karma: 6
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.28
  • MySQL version: 5.5.31-1
  • PHP version: 5.3.27
Re: Inline editing of custom data
August 15, 2014, 09:22:49 am
I modified the file
api/v3/Generic/Setvalue.php so that it looks like this:
Code: [Select]
// Customisation: setFieldValue below doesn't support custom data,
  // so if we encounter custom data we use the api create call instead
  if ( array_key_exists('custom_group_id', $fields[$field]) ) {
    $updateCustomFieldParams = array(
      'version' => 3,
      'sequential' => 1,
      'id' => $id,
      $field => $value,
    );
    $updateCustomFieldResult = civicrm_api($entity, 'create', $updateCustomFieldParams);
   
    if ( !civicrm_error($updateCustomFieldResult) ) {
      $entity = array('id' => $id, $field => $value);
      CRM_Utils_Hook::post('edit', $entity, $id, $entity);
      return civicrm_api3_create_success($entity);
    }
    else {
      return civicrm_api3_create_error("error assigning $field=$value for $entity (id=$id)");
    }
  }
  elseif (CRM_Core_DAO::setFieldValue(_civicrm_api3_get_DAO($entity), $id, $field, $value)) {
    $entity = array('id' => $id, $field => $value);
    CRM_Utils_Hook::post('edit', $entity, $id, $entity);
    return civicrm_api3_create_success($entity);
  }
  else {
    return civicrm_api3_create_error("error assigning $field=$value for $entity (id=$id)");
  }
}

Sharing it in case it's useful for others!
If you like empowering charities in a free and open way, then you're going to love Civi.

Email Amender: https://civicrm.org/extensions/email-amender
UK Phone Validator: https://civicrm.org/extensions/uk-phone-number-validator
http://civifirst.com
https://twitter.com/civifirst

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Inline editing of custom data

This forum was archived on 2017-11-26.