Posted by BrianJubal on May 15, 2009 at 3:40pm
Jump to:
| Project: | editablefields |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
| Issue tags: | Ajax, computed fields, editablefields, update |
Issue Summary
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
#1
I'd like that too - :-)
#2
Me too!
#3
me too
#4
There was some kind ajax refresh module, that helps in this problem.
#5
bfr would you describe your solution? Thanks!
#6
#7
Couldn't this be done by adding this to the editablefields.js file?:
$(document).ajaxStop(function() { location.reload(true); });#8
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);
}
}
#9
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.
#10
hi dogboy. how's your testing so far? going good?
#11
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?
#12
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?
#13
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.