I have some editable fields that are used by my computed fields. I'd like to make it so that when one of these editable field is updated, the computed fields are also updated. Right now the computed field is computed (I assume because node_save is called), but it is not displayed until the user refreshes the screen.

Comments

markfoodyburton’s picture

I'd like that too - :-)

LEternity’s picture

Me too!

astuteman247’s picture

me too

bfr’s picture

There was some kind ajax refresh module, that helps in this problem.

LEternity’s picture

bfr would you describe your solution? Thanks!

LEternity’s picture

Version: 6.x-1.2 » 6.x-2.x-dev
dogboy72’s picture

Couldn't this be done by adding this to the editablefields.js file?:
$(document).ajaxStop(function() { location.reload(true); });

karenann’s picture

My problem is that I had Editablefield setup on a Content Type "Invoices" and I needed to update a computed field in "Purchase Order" when a field in "Invoices" was changed. In this case, "Invoices" were linked to a "Purchase Order" by a node reference.

I don't like editing modules, so here's what I did. It's not totally tested yet, but seems to work alright so far. It's still kinda hacky, but...

I created a new module mymodule and I'm grabbing the menu item that's called when editablefields submits to make my own function.

function mymodule_menu_alter(&$items) {
  $items['editablefields_submit']['page callback'] = 'mymodule_editablefields_submit';
}

function mymodule_editablefields_submit(){
 // actions to be put here
}

I then grabbed the entirety of editablefields_submit() from editablefields.module and pasted it into my new function. Now for the editing:

Since computed fields update on save, I simply needed to execute a save on the referenced node.

I looked for node_save($node), which is what saves the "Invoice" fields and did the following:

// The following chunk is from editablefields_submit(). Editing the copy pasted into mymodule_editablefields_submit

      if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) {
        if ($node->{$field_name}[$delta] != $form_state['values'][$field_name][0]) {
          $node->{$field_name}[$delta] = $form_state['values'][$field_name][0];
          node_save($node);
          // ADDED CUSTOM FUNCTION to process our own crap as needed.
          mymodule_editablefields_save_referenced_node($node, TRUE);
        }
      }
      else {
        if ($node->{$field_name} != $form_state['values'][$field_name]) {
          $node->{$field_name} = $form_state['values'][$field_name];
          node_save($node);
          // ADDED CUSTOM FUNCTION to process our own crap as needed.
          mymodule_editablefields_save_referenced_node($node);
        }
      }

I then added a new function that's called above.

function mymodule_editablefields_save_referenced_node($node, $multiple = FALSE) {
  // Replace all this with your own.
  // I'm not using this in instances of multiple values, so I omitted it.
  if (!$multiple) {
    $ref = $node->field_your_referenced_node[0]['nid'];
    $node = node_load($ref);
    node_save($node);
  }
}
dogboy72’s picture

Ironically, I too am working with a content types named "Purchase Order" and "Purchase Order Details" with the latter having a node reference to the former. Your solution looks good and I agree its better not to hack a module, but in my case this is the only field (so far) that uses editablefields.

I'll give it a try. Thanks for sharing.

amal850720’s picture

hi dogboy. how's your testing so far? going good?

ledom’s picture

Thank you dogboy72

Using your tip allow to reload the page and get computed fields updated. We lose benefits of ajax saving but at list it works.

Is there a way to reload only the line where there is the update?

amal850720’s picture

thanks too do dogboy72. it works fine with a simple single line of code.

i guess it'll be a lot better if only the computed field is updated, instead of the whole page. is there a way to do so?

snoopy_tn’s picture

The 1-line fix in post #7 doesn't seem to work for the D7 version. I'm trying to get this to work with check boxes. Any help would be appreciated.

danisha’s picture

The 1 line fix on post #7 doesnt work on drupal 6 also. Its useless. The whole page loads again and again continuously. I need some working fix on this. The editable field on node view page, when edited is saved in the database. But the computed field doesnt have an option to be made an editable field which can change. There has to be some solution for this. please help.

mengi’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Per https://drupal.org/node/2148735, 6.x is longer maintained so issue is closed. If you wish to be a maintainer of the 6.x branch please create a new issue.