I have a text field with rich text format. I need to add a new line character if the length of a sentence exceeds 65 characters. When I edit the text value using javascript the formating breaks and the signature event fails eventually. Is there a way to edit the body of the text field value? I realized that the value is store in text/html.
below is sample:
Before edit:
<txtOtherDocuments><body xmlns="http://www.w3.org/1999/xhtml" xfa:APIVersion="Acroform:2.7.0.0" xfa:spec="2.1">
<p style="margin-top:0pt;margin-bottom:0pt;font-family:Arial;font-size:8 pt;text-decoration:none">Test Data</p></body>
Using field.rawValue="...." fails. Is there a different set of commands?
Please help.
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
If you want to access the data and its styling in a richtext field you have to use the command Fieldname.value.exData.saveXML("pretty"). This will give you the xHTML format of the data. Then you can manipulate the data the way you wish and to get it back into the field you have to use the Fieldname.value.exData.loadXML("xml to load", parm1, parm2). The parms are boolean values that will control whether to replace or append the xml to the existing xml. Refer to the Help/Scripting reference for a more detailed description.
Note that this will not be easy if there is lots of rich Text in your field as the text will be spread out between tags. You may have to use the rawValue (no formatting to know where to put the CR then find it in the HTML and add it there.
Make sense?
Paul
Views
Replies
Total Likes
If you want to access the data and its styling in a richtext field you have to use the command Fieldname.value.exData.saveXML("pretty"). This will give you the xHTML format of the data. Then you can manipulate the data the way you wish and to get it back into the field you have to use the Fieldname.value.exData.loadXML("xml to load", parm1, parm2). The parms are boolean values that will control whether to replace or append the xml to the existing xml. Refer to the Help/Scripting reference for a more detailed description.
Note that this will not be easy if there is lots of rich Text in your field as the text will be spread out between tags. You may have to use the rawValue (no formatting to know where to put the CR then find it in the HTML and add it there.
Make sense?
Paul
Views
Replies
Total Likes
Thanks Paul. Having the field set to accept Rich Text, doesn't allow control of font in a consistent manner. I switched back to Plain Text.
Could you please tell me how to add a new line in a Plain Text field? I did an export of the form and found that 
 is used as the new line character.
When I add a new line character, the text appears as is (dave
rita, instead of dave in one line and rita in the next line). I guess the characters are not recognized.
Here's what I'm doing:
var str = field1.rawValue;
//logic to check if the length is more that 65 characters. This result is an array with strings less than 65 characters
//finally I join the strings
field1.rawValue = lines.join("
");
I tried to escape characters and such but no luck.
Thanks,
RT
Views
Replies
Total Likes
\n is the newline char in javascript
Paul
Views
Replies
Total Likes
Hi Paul,
However, the following doesn't work. I'm not able to split based on the new line character. Please help.
var value = field1.rawValue;
var lines = value.split("\n");
Thanks,
Ram
Views
Replies
Total Likes
Hi Ram,
I think you want the carriage return character.
Try;
var lines = value.split("\r");
which is the same as;
var lines = value.split("\x0D");
Bruce
Works fine for me ......I did not use the var name value .....that is a reserved word .....try changing it to Fvalue instead and see if it works for you.
Paul
Views
Replies
Total Likes
Thanks Bruce and Paul!
Views
Replies
Total Likes
Hi Paul,
Both the new line and carriage return will cause the text to be displayed on multiple lines in Designer.
But it is only the carriage return which is escaped as 
 in the XML.
The new line (with a character code of 10) does not need to be escaped in the XML and in the xml view I use I get the value broken over two lines.
Regards
Bruce
Views
Replies
Total Likes
Views
Likes
Replies