Copy link to clipboard
Copied
I have a fillable PDF form field that has "allow rich text formatting" turned on, but when I click out of the field it un-bolds. I have a calculation script on there and a validation script and I'm not sure if that's why it's not working because all other fields without that will BOLD. I'm not sure how to get it to stay bold.
Copy link to clipboard
Copied
Yes. The calculation script overwrites the value you enter into it manually. You can't have it both ways...
In order for it to be bold you need to apply an array of Span objects in the calculation script to event.richValue and specify the fontWeight so the text appears as bold.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Rich text is created by using the Span object. Here's the entry in the JavaScript Reference:
The "richValue" of a field is composed of an array of span objects. Each span represents text in a specific style. For calculated field there is only one span. So to bold a calculated value you have to set the "fontWeight" property of this single span.
Add this code to the bottom of the calculation script
spans = event.richValue
spans[0].fontWeight = 900
event.richValue = spans
Copy link to clipboard
Copied
This script is in the valdition section and it didn't bold it. I typed:
if (event.value>18)
event.value=18;
spans = event.richValue
spans[0].fontWeight = 900
event.richValue = spans
Copy link to clipboard
Copied
Ahh, I see what is happening. It appears that setting the uncommitted value (event.value) decouples the rich value from the process. So we have to work purely in the rich value.
Try this:
spans = event.richValue;
if (event.value>18)
spans[0].text="18";
spans[0].fontWeight = 900;
event.richValue = spans;
Notice how every line ends with ";" and the line after the "if" is indented. It helps is you properly format the code. Especially when posting for other people to read.
Copy link to clipboard
Copied
I copy and pasted it and now it's even going over 18%. It should aways stay at 18% max, and it did not bold. It's okay though, i'll just have to go with these few text fields not bold. Thank you for your help!!
Copy link to clipboard
Copied
Try this code:
if (event.richValue) {
var spans = event.richValue;
if (Number(spans[0].text)>18)
spans[0].text="18";
spans[0].fontWeight = 900;
event.richValue = spans;
}
Copy link to clipboard
Copied
I is still unfortunately the same. 😞
Copy link to clipboard
Copied
What font is the field using?
Copy link to clipboard
Copied
Works fine for me. See: https://drive.google.com/file/d/1UrGHdge21g9Xev2hjrCcpRnHbXRhniwS/view?usp=sharing
Copy link to clipboard
Copied
My code worked fine as well. I think there must be something beyond the validation script. Maybe a formatting script. Or an odd font that won't bold.
Copy link to clipboard
Copied
I am trying to bold all the fields with an interest rate in them. Please see below, I pasted the script into VARIABLE_INT_RATE_CA FIELD.
https://drive.google.com/file/d/1UrGHdge21g9Xev2hjrCcpRnHbXRhniwS/view?usp=sharing
Copy link to clipboard
Copied
This is the link I posted...
Copy link to clipboard
Copied
Gosh. Sorry about that. Try this one.
https://drive.google.com/file/d/16Po15TFHXM9CT6s34p2cW6xKpj7E2IfU/view?usp=sharing
Copy link to clipboard
Copied
You must set the field as having Rich Text Formatting. To be honest, though, I don't understand why you're doing this with a script. Just set the field to use a Bold font, and that's it... Even if you want to make it conditional there are easier ways of doing it, like changing the textFont property.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That was me, and it had nothing to do with it being bold. I was referring to it not being able to have both a calculated value and allow the user to enter a value into it at the same time.
Just go to Properties, Appearance and select a bold variant of the font you want to use, like "Helvetica Bold".
Copy link to clipboard
Copied
WOW, talk about inexperience on my part! It worked, thank you so much. I was definitely overcomplicating things.