Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I want to display the computed field in real time as the user fills out the form. So that it can add how many items requested and the total price BEFORE the form is submitted. Is this possible?
thanks
Comments
Comment #1
tlash CreditAttribution: tlash commentedI am interested in this as well.
Comment #2
palik CreditAttribution: palik commentedsubscribing
Comment #3
mErilainen CreditAttribution: mErilainen commented+1 This would be really awesome.
Is there any way to even fill some other CCK field with Computed Field when you create a new node?
Comment #4
jjjames CreditAttribution: jjjames commentedI actually got some custom jQuery to perfom this task as you can see below (this particular one is for webform, but should work on CCK too):
Comment #5
omisar CreditAttribution: omisar commentedI'm also using WEBFORM module and I 'been looking for a way to sum fields and show the total on another field before the form is submited , I try the script above from superjames but it doesnot work for me, I'm not a programmer , javascript or php guy so is hard to find why is not working , I would appreciate advice how to mmake this script works or another way to achive the same, thank You.
Comment #6
obrienmd CreditAttribution: obrienmd commentedI would be willing to sponsor a patch for this.
Comment #7
jjjames CreditAttribution: jjjames commentedIf you can reverse engineer it, that jquery I posted is how I did it and should be straight forward to make it work for your needs.
Comment #8
gapa CreditAttribution: gapa commentedI would like to use this code for custom cck fields. Where should I put the code above? Into page.tpl.php?
Comment #9
dharmanerd CreditAttribution: dharmanerd commentedin response to...
#3
mErilainen
yes. it's really easy, just create one computed field to do all of your computations, then assign any cck field the value of your calculations...
here's an example from my calculated field. I'm populating multiple cck fields with default values if the field is empty...
//CS PSF
$node->field_o_cs_psf[0]['value'] = NULL;
//%RETURN
$node->field_o_return[0]['value'] = 10;
//MB AMT
$node->field_o_mb_amt[0]['value'] = 2 + $node->field_o_return[0]['value'];
each time the node saves, the existing value of the fields above will be overwritten. if you only need this to happen once, or just if the field is empty you can do things like...
if (the field has a value do nothing)
} else there is no value {
set a default (like above)
}
Comment #10
tomsm CreditAttribution: tomsm commentedsubscribing
Comment #11
Problue Solutionssubscribing
Comment #12
joecanti CreditAttribution: joecanti commentedsubscribing
Comment #13
118218 CreditAttribution: 118218 commentedsubscribing
Comment #14
Shawn DeArmond CreditAttribution: Shawn DeArmond commentedLooks like most development on this is now in the 7.x version. Moving. Also, it's a "feature request".
Comment #15
haradhansharma CreditAttribution: haradhansharma commentedsubscribing
Comment #16
rustyblue100 CreditAttribution: rustyblue100 commentedsubscribing
Comment #17
adamtong CreditAttribution: adamtong commentedsubscribing
Comment #18
8bitplateau CreditAttribution: 8bitplateau commentedI needed this too, so did a little hacking around.
I added a two extra field hooks to render a form element in the input form to act as a placeholder for displaying live js based calculations in
and added an extra field in the field settings form for entering javascript, in the computed_field_field_settings_form function.
together, they render a form element in the node input form which acts as a placeholder and executes the javascript you enter in the field settings using drupal_add_js inline.
this means that you have to write your JS as well as your PHP separetley.
they are not handled by the same function. this is because the calculated fields calulation is done by raw php input and does not translate to JS.
however if this module was to provide and interface similar to conditional fields dependenices form, where the user selects how the calcualtion is handeled, then the settings can be translated into both php and js.
so in away it does compliment the raw php input by providing raw js input and in both cases can be pretty dangerous and break stuff.
example uses can be like mentioned above
hope this helps as an idea :)
Comment #19
8bitplateau CreditAttribution: 8bitplateau commentedactually
js inline needs to be added in footer or has no affect
and example needs to be like;
in the settings form
Comment #20
adigunsherif CreditAttribution: adigunsherif as a volunteer commentedAn easier method that works for me:
in your .module file, we have
Then the js file is located in the same folder as the .module file, with the code below:
change "mymodule" to your module name and ensure you have picked the correct id of the field input.
Comment #21
adigunsherif CreditAttribution: adigunsherif as a volunteer commentedDoing this again with field collections (unlimited value). No PHP. simply add this js to your module and change the elements as needed.
This script adds a div with class .liveamount below the "rate"field for each . Within this div is where the calculation will appear for the user.
Comment #22
adigunsherif CreditAttribution: adigunsherif as a volunteer commentedhttps://www.drupal.org/node/3075055
Comment #23
cuman CreditAttribution: cuman commentedHi
Could you advise how to do it at 8?
Comment #24
baustin27 CreditAttribution: baustin27 commentedYes ill even chip in for payment to get this as a full module for D8 or even integrated into the computed field module itself. I feel this is a great feature for the world.