tag:blogger.com,1999:blog-7970679050025899967.post5251935020100168529..comments2023-11-24T03:56:57.923-08:00Comments on Adobe LiveCycle Designer Cookbooks by BR001: Programmatically updating Rich Text (or xHTML)BR001http://www.blogger.com/profile/02005650446661555680noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-7970679050025899967.post-86797963466979316072020-02-04T09:59:08.140-08:002020-02-04T09:59:08.140-08:00Actually, I tried everything. The only way was to ...Actually, I tried everything. The only way was to insert a dummy span element with white background after change the background color. It looks funny only when the field is in interactive data-entry mode. When in read-only mode or in static PDF, then it is fine.TarekAHFhttps://www.blogger.com/profile/15914538165615810959noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-89935987889349619142020-02-04T09:56:02.283-08:002020-02-04T09:56:02.283-08:00Actually, it worked! That was awesome! I had to ex...Actually, it worked! That was awesome! I had to execute the lines of code that will do the conversion in one shut, not one by one. That was a great help.TarekAHFhttps://www.blogger.com/profile/15914538165615810959noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-83817783865953517602020-02-03T04:49:29.609-08:002020-02-03T04:49:29.609-08:00Hi Tarek,
You might need some code like the follo...Hi Tarek,<br /><br />You might need some code like the following to convert a 'normal' text field to a rich text one;<br />if (TextField1.value.oneOfChild.className === "text") {<br /><br /> TextField1.value.nodes.remove(TextField1.value.text);<br /><br /> var exDataNode = xfa.form.createNode("exData");<br /><br /> TextField1.value.nodes.append(exDataNode);<br /><br />}BR001https://www.blogger.com/profile/02005650446661555680noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-82287751779290778062020-02-03T04:46:34.304-08:002020-02-03T04:46:34.304-08:00I was not able to get this to work either, you ca...I was not able to get this to work either, you can nest the span elements with the background-color style, so in this example only the word RED has a background color of Red<br /><br /><?xml version="1.0" encoding="UTF-8"?><br /><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><br /> <p><br /> <span style="background-color:#ffffff"><br /> Please click the<br /> <span style="background-color:#ff0000"><br /> RED<br /> </span><br /> Button<br /> </span><br /> </p><br /></body><br /><br />Probably doesn't help but maybe easier if you have to update when the field is disabledBR001https://www.blogger.com/profile/02005650446661555680noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-50759575223081254252020-02-01T18:23:08.396-08:002020-02-01T18:23:08.396-08:00Thanks a lot for this great article. I am unable t...Thanks a lot for this great article. I am unable to convert plain text field to rich text field using script sample provided. I get error "Invalid append operation: value cannot have a child element of exData. The element [exData] has violated its allowable number of occurrences.". Also, when I use background-color then try to reset it to white, it will look funny. Can I disable the color or use transparent background color?TarekAHFhttps://www.blogger.com/profile/15914538165615810959noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-15942109571943526472020-01-30T20:26:58.464-08:002020-01-30T20:26:58.464-08:00How can you reset the background color to none or ...How can you reset the background color to none or transparent after to set it? This is because the background color is applied to the end of the field after it is set. I tried everything I thing of nothing worked. I tried using white color but it looks funny when the field is active. Can you help please? TarekAHFhttps://www.blogger.com/profile/15914538165615810959noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-38749964990976940582016-02-23T23:18:02.924-08:002016-02-23T23:18:02.924-08:00Underlining is a bit different, because there is d...Underlining is a bit different, because there is double underline, word underline and double word underline. If you wanted to clean those up to just an underline you would want the following after <br /><br /> if ((p == "fontStyle" ...) <br /> {<br /> ...<br /> }<br /><br />to add<br /><br /> if (p == "underline" && spans[i][p]) <br /> {<br /> boldItalicSpan[p] = "underline";<br /> }<br /><br />If you want to keep the type of underlines then it would be just (p == "underline") after the pipes.BR001https://www.blogger.com/profile/02005650446661555680noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-35259668541869128672016-02-23T06:49:30.892-08:002016-02-23T06:49:30.892-08:00Thanks again, Bruce. Works perfectly.
One more ...Thanks again, Bruce. Works perfectly. <br /><br />One more silly question: if I want to keep underlines as well, do I just add p == "textDecoration" && spans[i][p] == "underline" after the pipes? Ari Josephhttps://www.blogger.com/profile/12743072295643678966noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-30828480088085483412016-02-22T18:55:27.199-08:002016-02-22T18:55:27.199-08:00Hi,
The xmlToSpans method doesn't handle all ...Hi,<br /><br />The xmlToSpans method doesn't handle all the formatting available so you may always have some problems. One thing that it doesn't handle is the style="xfa-spacerun:yes", without this then consecutive white space (including line breaks) will get lost.<br /><br />You could try changing the code <br /><br />if (spans[i].endParagraph)<br />{<br /> boldItalicSpan.endParagraph = spans[i].endParagraph; <br />}<br /><br />to <br /><br />if (spans[i].endParagraph)<br />{<br /> boldItalicSpan.endParagraph = spans[i].endParagraph;<br /> if (spans[i].text == " ")<br /> {<br /> boldItalicSpan.text = "\u2028";<br /> boldItalicSpan.endParagraph = false;<br /> }<br />}<br /><br />Which might get you closer to what you want.<br /><br />So the xHTML <p><span style="xfa-spacerun:yes"> </span></p>, which represents a paragraph mark in the original rich text, just comes though as a space but with the endParagraph set to true. The change in code above replaces this with an actual line break character ... the sort that doesn't get collapsed in XML. <br /><br />And then this will only work with Reader 9 and later.<br /><br />There are some examples of using E4X in this blog to handle rich text, which is harder but does get you more control.<br />BR001https://www.blogger.com/profile/02005650446661555680noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-62706190479273573472016-02-22T09:08:23.041-08:002016-02-22T09:08:23.041-08:00Thanks, Bruce! Works as advertised. The only small...Thanks, Bruce! Works as advertised. The only small glitch I'm having is that it's also removing line and paragraph breaks. Any idea on what's going wrong? Ari Josephhttps://www.blogger.com/profile/12743072295643678966noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-42072589310665703652016-02-22T04:38:06.316-08:002016-02-22T04:38:06.316-08:00Hi, You should be able to do a similar thing as Jo...Hi, You should be able to do a similar thing as Jonathon in the exit event of the field so when they leave the field any unwanted formatting is removed. That is;<br /><br />var spans = util.xmlToSpans(TextField1.value.exData["##xHTML"].saveXML()); <br />var boldItalicSpans = [];<br />for (var i = 0; i < spans.length; i++)<br />{<br /> var boldItalicSpan = {};<br /> if (spans[i].text)<br /> {<br /> boldItalicSpan.text = spans[i].text; <br /> }<br /> if (spans[i].endParagraph)<br /> {<br /> boldItalicSpan.endParagraph = spans[i].endParagraph; <br /> }<br /> for (var p in spans[i])<br /> {<br /> if ((p == "fontStyle" && spans[i][p] == "italic") || (p == "fontWeight" && spans[i][p] == 700))<br /> {<br /> boldItalicSpan[p] = spans[i][p];<br /> }<br /> }<br /> boldItalicSpans.push(boldItalicSpan);<br />}<br /><br />var xHTML = util.spansToXML(boldItalicSpans);<br />TextField1.value.exData.loadXML(xHTML, false, true);<br /><br />Here's a link to a form to make sure the code actually works, https://sites.google.com/site/livecycledesignercookbooks/home/BoldItalic.pdf?attredirects=0&d=1.<br /><br />If you want to remove line feeds then remove the "endParagraph" code.<br /><br /><br /><br />BR001https://www.blogger.com/profile/02005650446661555680noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-53508292652775382972016-02-16T07:37:54.815-08:002016-02-16T07:37:54.815-08:00Hi Bruce,
I have a much simpler request (though t...Hi Bruce,<br /><br />I have a much simpler request (though this was helpful as context): I'm just trying to restrict the rich text formatting in a text field to bold and italic. Is this something I can do in xHTML? Ari Josephhttps://www.blogger.com/profile/12743072295643678966noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-82579173106443919782014-05-13T15:36:56.683-07:002014-05-13T15:36:56.683-07:00Hi Jonathan,
I'm glad you found the post a he...Hi Jonathan,<br /><br />I'm glad you found the post a help, extracting the plain text from a caption should be as easy as;<br /><br />console.println(TextField1.caption.value.exData["##xHTML"].value);<br /><br />You could also loop though each element, <br /><br />var spans = util.xmlToSpans(TextField1.caption.value.exData["##xHTML"].saveXML()); <br />var plainText = [];<br />for (var i = 0; i < spans.length; i++)<br />{<br /> if (spans[i].text)<br /> {<br /> plainText.push(spans[i].text)<br /> }<br />}<br />console.println(plainText.join(""));<br /><br />Good luck<br /><br />Bruce<br /><br /><br />BR001https://www.blogger.com/profile/02005650446661555680noreply@blogger.comtag:blogger.com,1999:blog-7970679050025899967.post-40840921741762328952014-05-13T06:47:51.505-07:002014-05-13T06:47:51.505-07:00Hi,
Thanks for this great post ! I've been tr...Hi,<br /><br />Thanks for this great post ! I've been trying to play with rich text in LiveCycle for a while and you pointed out some really useful informations.<br /><br />I have one question. Do you know how I could convert a rich text caption into a plain text caption ?<br />I need to export the caption of a field into another text field but it doesn't work if I have italic and normal text into the same caption field.<br /><br />Thanks alot !Anonymoushttps://www.blogger.com/profile/13584471174168528194noreply@blogger.com