Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hi,
is it possible to add an suffix and/or a prefix to the calculated field? Like adding a dollar or euro-sign before or after the calculated numbers?
Thanks,
Oscar
Comments
Comment #1
Moonshine CreditAttribution: Moonshine commentedIf you're saving computed values as being purely numeric, then you can just add the formatting via the "Display Format" section of the computed field. Something like this may work for you:
Comment #2
oscarelloo CreditAttribution: oscarelloo commentedThanks! That works great. One thing though, if I add the code above, the field will always print, even if it is empty. I would rather see that this does not happen. Any suggestions?
Comment #3
Moonshine CreditAttribution: Moonshine commentedSure.. you'll probably just want to check for a value.. something like:
Comment #4
oscarelloo CreditAttribution: oscarelloo commentedThanks for your quick response!
I'm trying my best to get your code to work, but the field stills print.
Comment #5
oscarelloo CreditAttribution: oscarelloo commentedNevermind - solved it. I only removed the ";" after the first line.
I have never before coded in php (just some Pascal...), so I hope this solution is ok.
Comment #6
oscarelloo CreditAttribution: oscarelloo commentedDamn.
I works, the field is hidden when empty and prints when numbers are added. But I do get a syntax error for that unclosed line:
So I guess you always have to close the arguments. Any other ideas?
Comment #7
Moonshine CreditAttribution: Moonshine commentedWell you definitely don't want to remove the semicolon. Really what I had there should work. What are you seeing displayed when there is no value?
Comment #8
oscarelloo CreditAttribution: oscarelloo commented$ 0.00
is displayed if the field is left empty.
/ Oscar
Comment #9
Moonshine CreditAttribution: Moonshine commentedahh.. well that looks like the value isn't really "empty", rather it's set to 0. Try this instead:
Comment #10
oscarelloo CreditAttribution: oscarelloo commentedYOU RULE! :)
Now it all works like a charm!
Thanks again for all your fast and precise help. I really appreciate it.
/ Oscar
Comment #11
Moonshine CreditAttribution: Moonshine commentedComment #12
Witch CreditAttribution: Witch commented@ 9
The "$" sign is in this case a prefix. i tried to add a suffix but without any success. may you post an example where the "$" is a suffix?
Thank you!
Comment #13
Witch CreditAttribution: Witch commentedNext time i just should try to open my eyes.
Comment #14
vicentefoxxx CreditAttribution: vicentefoxxx commentedWell I am trying to add the prefix but is not working i tried what is sugested in post 13# with prefix and is working
This is the code that is not working:
if (!empty($node_field[0]['value'])) { // the node is not new
return $node_field[0]['value'];
}
else { // the node is new
$count = db_result(db_query("SELECT COUNT(*) from {node} WHERE type = 'expeborrar'"));
$node_field[0]['value'] = '$' . $count + 1000;
}
And this one is working but only with prefix:
if (!empty($node_field[0]['value'])) { // the node is not new
return $node_field[0]['value'];
}
else { // the node is new
$count = db_result(db_query("SELECT COUNT(*) from {node} WHERE type = 'expeborrar'"));
$node_field[0]['value'] = $count + 1000 . '-2011';
}
Thanks!
Comment #15
vicentefoxxx CreditAttribution: vicentefoxxx commentedComment #16
braindrift CreditAttribution: braindrift commentedHi vicentefoxxx,
you should add the prefix or the suffix in the "Display Format" textarea. In the "Computed Code" textarea you should specify the raw value that should be seved in the DB.
Comment #17
braindrift CreditAttribution: braindrift commentedComment #18
vicentefoxxx CreditAttribution: vicentefoxxx commentedAhhhhhhhhhhhhhhhhhh great dendi, is working great I just write the code for the people like me that dont understand a lot of PHP Syntax thank you very much :)
Just copy this in "Display Format" textarea and change the prefix or sufix for the wanted data.
$display = 'prefix' . $node_field_item['value'] . 'sufix';
Comment #19
cj-a-min CreditAttribution: cj-a-min commentedNice work everyone!
The above works great for not displaying the content, if there is no content to be displayed. And if there is content than it adds the prefix and suffix.
But, how about stopping the computed code from running unnecessary queries, if there is no data to begin with? For example.
The Computed Code:
Now we have to stop the query from happening in the "computed code" if there is no USD amount to begin with. So the computed code would look like this:
The New Computed Code, which needs some Luvn:
You can keep the display code, as a second attempt at stopping from displaying the field, and of course to add prefix and suffix:
The code 'stop everything and return a value of NULL' is what I am looking for? Anyone know how to do this? Or maybe I'm on the wrong track all together :\
Comment #20
dqdDue to the Drupal core life cycle policy and security support advisery, Drupal 6 is no longer supported. So issues for Drupal 6 cannot be longer maintained. The project maintainer has asked for closing all D6 issues to clean up the issue queue. Feel free to reopen the issue if required or set it to "needs to be ported" and latest D8 dev version, if the issue discusses a still missing feature which can be implemented in the D8 version.