Copy link to clipboard
Copied
Hi guys,
I'm preparing an form for my job and having trouble finding this answer. The form is for a list of training courses. The user should be able to select a training course from a Dropdown List, then have a corresponding Text Field populate with the description of their selected training course.
I understand how to do that part. What I am stuck on is how to force the Text Field(for the Course Description) to hold my custom formatting (as in random line spacings, some bolded sub-headers, bullet points, indents, etc.). The course descriptions are several paragraphs long so they can't just be a solid wall of text.
I have Multi-line and Allow Rich Text Formatting selected under the Text Field properties. I also then exited Prepare Form mode, selected the text and pressed Ctrl+E to enter the Form Field Text Properties. I do see these options but it does not appear to allow for random custom spacing, at least in my case where the text is being populated by the Export Value of a Dropdown list item. That Export Value is simply a solid box...you can write as much as you like in there, but cannot (as far as I can tell) skip lines or anything.
What do you guys think? Can this be done by using one text field? Or perhaps I have to export the course description across several text fields which are pre-spaced and formatted to my liking? This sounds very time consuming and difficult if so. Especially if I am trying to perform the same task for several items in the drop down menu, all with descriptions of differing length and formatting.
Pic below of what I'm trying to accomplish
Any guidance is very welcome. Thank you!
 
It's case-sensitive, so it's should be 'richText' not 'richtext'.
Try like this:
var drop = this.getField("Course").valueAsString;
event.target.richText = true;
event.target.multiline = true;
var spans = new Array();
spans[0] = new Object();
spans[0].text = drop;
spans[1] = new Object();
spans[1].text = "Executive";
spans[1].textColor = color.blue;
spans[1].textSize = 18;
spans[2] = new Object();
spans[2].text = "Overview";
spans[2].textColor = color.red;
spans[2].textSize = 20;
event.richV
...
You can do it like this:
var drop = this.getField("Course").valueAsString;
event.target.richText = true;
event.target.multiline = true;
switch(drop){
case "Oranges":
var spans = new Array();
spans[0] = new Object();
spans[0].text = drop;
spans[1] = new Object();
spans[1].text = "Big round fruit";
spans[1].textColor = color.blue;
spans[1].textSize = 18;
event.richValue = spans;
break;
case "Apples":
var spans2 = new Array();
spans2[0] = new Object();
spans2[0].text = drop;
spans2[1] = new O
...
Copy link to clipboard
Copied
Instead of export value, you can write text in script the way you want it to look.
Copy link to clipboard
Copied
Agreed, but just want to clarify that in order for it to look like that you will have to set the text field as having Rich Text Formatting and use a script to apply an array of Span objects, each one containing a single string with its own format. Then apply that array to the field's richValue property to have it displayed.
Copy link to clipboard
Copied
Thank you both. I am assuming the script should be applied under the Dropdown properties under Format--> Custom Format Script?
Copy link to clipboard
Copied
No. Either custom Validation of the drop-down, or custom Calculation of the text field.
Copy link to clipboard
Copied
I am utilizing the JavaScript reference guide for Rich Value - Type, Array of Span Objects. In trying to both retrieve a value from another field and apply rich text formatting to the text field, I tried out something like this but it is not working:
//I thought this would retrieve "Course" item from my drop-down, and then add the words Executive Overview, formatted for blue and red text respectively. But none of that is happening. Sorry if this is way off..any help appreciated.
event.value = this.getField("Course").value;
f.richtext = true
f.multiline = true
var spans = new Array();
spans[0] = new Object();
spans[0].text = "Executive";
spans[0].textColor = color.blue;
spans[0].textSize = 18;
spans[1] = new Object();
spans[1].text = "Overview";
spans[1].textColor = color.red;
spans[1].textSize = 20;
f.richValue = spans;
Copy link to clipboard
Copied
It's case-sensitive, so it's should be 'richText' not 'richtext'.
Try like this:
var drop = this.getField("Course").valueAsString;
event.target.richText = true;
event.target.multiline = true;
var spans = new Array();
spans[0] = new Object();
spans[0].text = drop;
spans[1] = new Object();
spans[1].text = "Executive";
spans[1].textColor = color.blue;
spans[1].textSize = 18;
spans[2] = new Object();
spans[2].text = "Overview";
spans[2].textColor = color.red;
spans[2].textSize = 20;
event.richValue = spans;
You didn't add any space or new line, for space leave one empty character like this "Overview " or drop+" ".
For new line use like this "Overview\n".
Copy link to clipboard
Copied
Nesa,
You are very helpful and most of this makes sense to a beginner like me.
Your code works well but I am also attempting to populate a second text field a with a simple price based on the course selction. I was previously doing this by utilizing the Export Value under the Dropdown properties. So it looked like this:
Export Value: Course Description--$1,000
\\for course description text field
event.Value = this.getField("Course").value.split("--")[0];
\\for Price text field
event.Value = this.getField("Course").value.split("--")[1];
Using the above lines of code coupled with the ones you shared no longer seems to work exactly right. Do I need to ditch the Export Value altogether and try something else?
Thank you again
Copy link to clipboard
Copied
You don't need export value for that, let's say that text field is called "Text field2" as 'validation' script of dropdown field use something like this:
var f = this.getField("Text field2");
switch(event.value){
case "item1":
f.value = 1000;
break;
case "item2":
f.value = 2000;
break;
case "item3":
f.value = 3000;
break;
default:
f.value = "";}
"item1","item2"...etc are just examples of dropdown choices, you change those to your actual choices in dropdown.
Copy link to clipboard
Copied
Nesa,
Thank you again. This works well and I'm excited to keep practicing using some of the code you've given me!
Copy link to clipboard
Copied
Nesa,
I ran into one other issue. This code does work. The problem is it is lacking a way of changing based on the Drop down menu item selection. I believe what I currently have will apply to any of the drop down items selected.
Is there an easy way to incorporate dropdown menu selection into this array?
Copy link to clipboard
Copied
I'm not sure that I understand, what array?
Please post the script you used.
Copy link to clipboard
Copied
Sorry, I meant this array of span objects you gave me. So overall, I have 1 dropdown list with called 'Course'. Then I have two separate text fields populating based on the selection of the Course dropdown list. The first text field is 'Course Description' for which I need the rich text formatting. I am using the following code...I guess it works but does not change depending on the item selected from the Dropdown. Is this perhaps where Nested Arrays come into play? And each nested array would be 'linked' to a particular dropdown selection?
var drop = this.getField("Course").valueAsString; event.target.richText = true; event.target.multiline = true; var spans = new Array(); spans[0] = new Object(); spans[0].text = drop; spans[1] = new Object(); spans[1].text = "Executive"; spans[1].textColor = color.blue; spans[1].textSize = 18; spans[2] = new Object(); spans[2].text = "Overview"; spans[2].textColor = color.red; spans[2].textSize = 20; event.richValue = spans;
Copy link to clipboard
Copied
Variable 'drop' contains dropdown value so that part should change when you change dropdown selection.
If you want to change text 'Overview' and 'Executive' for each dropdown selection, then you can create another spans object for those texts.
Copy link to clipboard
Copied
lol im so lost..i've been troubleshooting this literally all day but its not working how i need.
The Variable drop does seem to be working as intended. What is not working properly is the additional text. So Lets say my Dropdown menu is populated with these selections: 'Apples', 'Oranges', 'Grapes'
The Drop variable is indeed working properly, populating the text field with 'apples', 'Oranges', 'Grapes', respectively. But this following code remains in the text field regardless of the selection. I need to assign different objects/texts to each individual dropdown selection. So for example..if I select 'Oranges' from the dropdown box, the text box would populated with 'Oranges' + 'Big round fruit' for example. Then if I select 'Apples', the text box would populate with 'Apples' + 'red delicious' for example. And the text needs to be formatted as rich text with random spacing as we discussed before.
Is there something additional I would need to do to accomplish this?
Thanks for your patience with me
Copy link to clipboard
Copied
You can do it like this:
var drop = this.getField("Course").valueAsString;
event.target.richText = true;
event.target.multiline = true;
switch(drop){
case "Oranges":
var spans = new Array();
spans[0] = new Object();
spans[0].text = drop;
spans[1] = new Object();
spans[1].text = "Big round fruit";
spans[1].textColor = color.blue;
spans[1].textSize = 18;
event.richValue = spans;
break;
case "Apples":
var spans2 = new Array();
spans2[0] = new Object();
spans2[0].text = drop;
spans2[1] = new Object();
spans2[1].text = "red delicious";
spans2[1].textColor = color.red;
spans2[1].textSize = 18;
event.richValue = spans2;
break;
default:
event.value = "";}
Copy link to clipboard
Copied
Ah I see. Yes, this works perfectly. Thank you again Nesa, you're awesome.