Copy link to clipboard
Copied
I have 30 comment fields in my form and I want to consolidate it to 1 field.
However, users have an option to just use how many comment fields they like. That means 1-30.
The comment fields have a default value, "Comment -1", "Comment-2" etc.
Since the fields have default value, is there a way to combine items only if it has content, meaning users have put in a real content in the field and not just the default value?
Right now this is how the form looks like. The script I have is only written up to comment 4 that's why comments 5-30 is not visible.
I want the summary field to show only comments 1 and 2, with the "comments#".
Thank you in advance.
Copy link to clipboard
Copied
You can use this code as the custom calculation script of your text field:
var text = "";
for (var i=1; i<=30; i++) {
var s = this.getField("Comment-"+i).valueAsString;
if (s!="") text+="Comments-"+i+": " + s + "\r";
}
event.value = text;
Copy link to clipboard
Copied
You can use this code as the custom calculation script of your text field:
var text = "";
for (var i=1; i<=30; i++) {
var s = this.getField("Comment-"+i).valueAsString;
if (s!="") text+="Comments-"+i+": " + s + "\r";
}
event.value = text;
Copy link to clipboard
Copied
Hey. Thank you for responding. Should I use this code for the summary field? I tried pasting this script and looks like it didn't work.
Might be another stupid question but the current field names of my comment fields are t_1, t_2, t_3, t_4 etc. Should I change the names in order for this code to work?
Copy link to clipboard
Copied
Yes, as the custom calculation script of the summary field.
OK, in that case you need to change either the names of the fields or the code.
Doing the latter is much easier... Simply change this:
var s = this.getField("Comment-"+i).valueAsString;
To:
var s = this.getField("t_"+i).valueAsString;
PS. When a code doesn't work the first thing you should do is look in the JS Console (Ctrl+J), as it will report any errors that happened while executing it, like an incorrect field name.
Copy link to clipboard
Copied
Gotcha. This script worked however, I needed to delete the default value "Comment -#:".. We need to have that in every comment field though. So users know that they can type in a comment per box. If I don't delete the default value then it will look like this.
Any idea on how to make that happen? Still have the "Comment -#:" per comment field but it won't duplicate in the summary if it has content and it won't show up if comment field wasn't used.
Copy link to clipboard
Copied
Just remove this part from the code: "Comments-"+i+": " +
Copy link to clipboard
Copied
Thank you so much for your help.
Copy link to clipboard
Copied
By the way, this should not happen if the fields are really empty. It seems your fields already contains the text "Comments-XX:"...
Copy link to clipboard
Copied
We just decided to use this code that you gave and ended up deleting the default values in the comment fields.
var text = "";
for (var i=1; i<=30; i++) {
var s = this.getField("t_"+i).valueAsString;
if (s!="") text+="Comments-"+i+": " + s + "\r";
}
event.value = text;
Thank you again so so much!
Copy link to clipboard
Copied
That's probably a better approach.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now