Thanks for the great work.

Right now, you can only have one field editable on a row. The last one on the row seems to win.

Comments

mstrelan’s picture

Actually, it seems that the last one that is saved will win. For example if you go an update column C, then column A then column B then the changes from column C and A will be lost and only column B is saved. You can refresh the page, edit column A, refresh, edit column C and then you'll get the desired result.

Without looking at the code I would guess that the original node object is stored and when you edit a field the original node + the change is saved to the database. When a field is edited the "original" that is stored also needs to be updated.

mstrelan’s picture

Status: Active » Needs work

I was able to solve this for nodes with the following:

<?php
function editablefields_form_submit(&$form, &$form_state) {
  $entity = $form_state['entity'];

  // Reload the node from the database
  $entity = node_load($entity->nid, NULL, TRUE);

  // ..... some text truncated

}
?>

This is obviously not the generic way to do it, but by setting $reset = TRUE you always get the latest from the database before saving. It is also rather inefficient, but perhaps necessary.

Damien Tournoud’s picture

Status: Needs work » Fixed

Should be fixed by b81e145, where I added the name of the field to the form ID.

Damien Tournoud’s picture

Status: Fixed » Needs work

Actually, it's not fixed.

The problem is that we are storing the entity in the form cache, and resaving the whole entity which overrides the changes you might have done in some other field.

mstrelan’s picture

Damien - any comment on the approach in #2? I am sure you would know of a beter way.

jerdavis’s picture

I used the approach in #2, with a minor change - this works well for me.

/**
 * Form submit callback: save the field modifications.
 */
function editablefields_form_submit(&$form, &$form_state) {
  $entity = $form_state['entity'];

  // Reload the node from the database
  $entity = node_load($entity->nid, NULL, TRUE);

  entity_form_submit_build_entity($form['#entity_type'], $entity, $form, $form_state);

  // Push the updated entity back into $form_state
  $form_state['entity'] = $entity;

  // TODO: needs a try / catch.
  entity_save($form['#entity_type'], $entity);
}
Damien Tournoud’s picture

Status: Needs work » Fixed

Fixed in commit e359ace, using a similar approach.

Damien Tournoud’s picture

Project: editablefields-d7 » Editable Fields
Version: » 7.x-1.x-dev

Moving the issues back to the main project.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.