RTF formating loss

P

Paulo

Hello all

I am trying to fill in a RTF control dynamically. But I loose the format...
Here are the basic steps I do:
* I create a new form in design mode.
* I drag and drop a RTF control on the form
* I save the form

Next:
* I open it to fill it
I fill the RTF control with text, newlines, strong, italic....
* I save the file under "Form2.xml" and close the file.

I then reopen the Form in Design mode, add the "Form2.xml" as a resource
file and add the following code to the onload event:

var AuditDOM = new ActiveXObject("Msxml2.DOMDocument.5.0");
AuditDOM.async = true;
AuditDOM.validateOnParse = false;
AuditDOM.load("Form2.xml");
XDocument.DOM.documentElement.childNodes.item(1).text =
AuditDOM.documentElement.childNodes.item(0).text;

Basically, I'm trying to take the value that the user entered in Form2 and
use that as a default value for the new form.


This works but I loose the formating. I tried with nodeValue but I get a
type mismatch. But when debugging I see that both nodes have the Element type.

By the way, I don't understand why the indexes aren't the same...
item(0) and item(1)...

Could someone please explain?
Thanks
 
G

Greg Collins [InfoPath MVP]

The best thing to do when wanting to fill in a rich text field manually, is
to first create a small form with a RTF, fill it in and save it. Then look
at the XML file to see just how InfoPath formats the HTML within that RTF.

You'll likely find that you are missing the required namespace.

Greg
 
P

Paulo

Thanks Greg for your response. but I'm afraid I don't get it.
What you said is what I've done. when a form filled and saved here is an
example of what I get:
<my:field1>
<div xmlns="http://www.w3.org/1999/xhtml"><strong>kjflsdkjf
sadsad</strong>dfsdfsdfsdf</div>
<div xmlns="http://www.w3.org/1999/xhtml">sdf</div>
<div xmlns="http://www.w3.org/1999/xhtml">sdf</div>
</my:field1>


If I try something like:
XDocument.DOM.documentElement.childNodes.item(1).text = "<div
xmlns=\"http://www.w3.org/1999/xhtml\"><strong>kjflsdkjf
sadsad</strong>dfsdfsdfsdf</div>";

I see the html not the interpreted html...
Do I need to set it with another method?
Am I missing/not understanding something?

Thanks
 
G

Greg Collins [InfoPath MVP]

2 keys to remember:

1. You cannot use .text = "" because that is exactly what it says, "text". That's why you see text. You need to create an HTML DOM and insert it into your RT node.

2. The namespace is very important. You only really need it once as a containing div with that namespace... then all the rest of your HTML can be inside of that div. But at least the outer-most element must have that namespace.

--
Greg Collins [InfoPath MVP]
Visit http://www.InfoPathDev.com


Thanks Greg for your response. but I'm afraid I don't get it.
What you said is what I've done. when a form filled and saved here is an
example of what I get:
<my:field1>
<div xmlns="http://www.w3.org/1999/xhtml"><strong>kjflsdkjf
sadsad</strong>dfsdfsdfsdf</div>
<div xmlns="http://www.w3.org/1999/xhtml">sdf</div>
<div xmlns="http://www.w3.org/1999/xhtml">sdf</div>
</my:field1>


If I try something like:
XDocument.DOM.documentElement.childNodes.item(1).text = "<div
xmlns=\"http://www.w3.org/1999/xhtml\"><strong>kjflsdkjf
sadsad</strong>dfsdfsdfsdf</div>";

I see the html not the interpreted html...
Do I need to set it with another method?
Am I missing/not understanding something?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top