I have a computed field that generates an order number. I wonder if it's possible to be able to edit the order number afterwards. In other words, is it possible to have an editable computed field?

Comments

yched’s picture

I think computed fields, by nature, can't be edited.
Maybe what you want is a regular number field, initialized using a 'default value' in the field's settings page ?

appel’s picture

Wow, you're fast! Thanks for your reply! Do you think it's possible to select the last order number from the database and increment it by 1 in the 'default value' of a regular number field? I currently have this query in my computed field:

SELECT `nid`, `field_projectnumber_value` FROM `content_type_content_project` WHERE `field_projectnumber_value` != '' ORDER BY `field_projectnumber_value` DESC LIMIT 1;

yched’s picture

You can define the default value using PHP code, so inside that code you can do whatever you see fit.
Be aware that 'default values' for fields only pre-fill the node _creation_ form with the defined value. Once the node is created, the default value does not come into play anymore, and the field can be edited just like any other one (unless you use write some code with hook_form_alter to hide it in forms)

appel’s picture

Thanks yched, I'll give it a try right away!

appel’s picture

Category: feature » support

Ooof, that's kinda hard. At this point it doesn't seem to return any data from the $node object:

global $node;
return array(0 => array('value' => $node->nid));

What am I doing wrong?

appel’s picture

Status: Active » Closed (fixed)

Nevermind, I got it working. Thanks!

colan’s picture

appel’s picture

Well if this isn't a blast from the past... :)