Jeremy,
Do you really mean that "nothing" happens?
I would expect one of two things to be likely to happen - either you
get a JScript error message or the literal string "\n" is added to the
text content of the rich text box.
I think what you want to do is not possible, in either JScript or
VBScript.
In VBScript you can't split a string literal across two lines so you
can't include an actual newline.
Similarly in JScript a statement must be terminated by a semicolon at
the end of the line.
So, if my logic is correct you can't do what you want to do with
either VBScript or JScript.
Andrew Watt
MVP - Microsoft InfoPath
Author "Microsoft InfoPath 2003 Kick Start", Sams Publishing
http://www.tfosorciM.org/blog/ - Reflecting on Microsoft
http://www.yahoogroups.com/group/InfoPath
http://www.yahoogroups.com/group/OneNote
http://www.yahoogroups.com/group/XForms
I don't know if this means anything, but when I feed the \n, I get
neither a jscript error, or the literal character showing in the box.
It just prints a blank space. Also, if this is not possible by script,
is it possible by any other means?
Jeremy,
That's odd.
Do you want to show your code? When I was testing it in JScript the \n
appeared literally in the rich text box.
I am at a very early stage in exploring the SP1 Preview so I don't
know if that can do it. But I don't think there is a way to achieve
what you want in the original release.
The content of a Rich Text Box is XHTML data. Just like HTML in web pages,
whitespace (spaces, tabs, newlines, etc) are all treated the same. You need
to use <P> or <DIV> elements instead
Since you are trying to modify the defaults content, the easiest thing to do
is to use File | Extract Form Files... to save the form template in an
expanded form (files in a directory). Then close the form template, open the
template.xml file in the directory in InfoPath, type what you want the
default value to be in the Rich Text Box, then save the file. Now
right-click on the manifest.xsf and select Design, and re-save the form
template as an XSN.
You can do this programatically too, e.g. in an OnLoad handler, set the
inner content of the node to which the Rich Text Box is bound to the
appropriate XHTML content. (I don't have the exact syntax handy, but if
that's the road you want to go down please reply and we'll get it sorted out
for you.)
Thanks very much for your help. Unfortunately I could not get the
desired results from those methods. I'd appreciate it if you could
show me what I am still doing wrong. Here is the code for the onLoad
handler that I tried:
XDocument.DOM.selectSingleNode("/my:PurchaseOrder/my:Pages/my:Page/my:BillTo").text
= "Priority One Packaging Machinery<P>815 Bridge Street Waterloo
ON<P>N2V 2M7"
The result is the box prints out the literal <P> tags.
And here is what I tried in the template.xml file:
<my:BillTo>Priority One Packaging Machinery<P>815 Bridge Street
Waterloo ON<P>N2V 2M7</my:BillTo>
Which gives me the InfoPath error
The following XML template file in the form is not valid: template.xml
The form contains XML that cannot be parsed:
End tag 'my:BillTo' does not match the start tag 'P'
when trying to design the manifest file.
Thanks for your time,
Jeremy
XDocument.DOM.selectSingleNode("/my:PurchaseOrder/my:Pages/my:Page/my:BillTo").text
= "Priority One Packaging Machinery\n815 Bridge Street Waterloo
ON\nN2V 2M7";
Which places space characters wherever the \n is into the rich text
box.
FYI, I am using the SP1 preview. I haven't discovered any new
functionality that would help me in this respect though.
Regards,
Jeremy
Unfortunately, you can't simply set tags into the "text" property - you need
to programatically create new elements. (Again, I'm working from home at the
moment and don't have all of my handy documentation with me...)
> And here is what I tried in the template.xml file:
>
> <my:BillTo>Priority One Packaging Machinery<P>815 Bridge Street
> Waterloo ON<P>N2V 2M7</my:BillTo>
>
> Which gives me the InfoPath error
Yep - that's not valid XHTML. XHTML is always well-formed XML - start and
end tags must match, namespaces must be correct, etc. Replace it with this
instead:
<my:BillTo>
<div xmlns="http://www.w3.org/1999/xhtml">
Priority One Packaging Machinery
</div>
<div xmlns="http://www.w3.org/1999/xhtml">
815 Bridge Street Waterloo ON
</div>
<div xmlns="http://www.w3.org/1999/xhtml">
N2V 2M7
</div>
</my:BillTo>
Note that you can also simply open the template.xml file *in InfoPath* and
it will let you edit the template.
Sorry, but I don't have any examples handy, but hopefully someone sees this
and can provide one.
thanks,
Brian
"Jeremy Chamilliard" <jchami...@priorityone.ca> wrote in message
news:f2e98372.04030...@posting.google.com...
>InfoPath rich text fields are XHTML fields. In order to get formatting,
>including line breaks, into the field you will have to manipulate the XHTML
>like an XML DOM. You can get to the node like you've tried, by using
>selectSingleNode, but after that you'll have to do things like .append() to
>insert a <br> tag. Also note that you'll have to keep those tags in the
>XHTML namespace.
>
>Sorry, but I don't have any examples handy, but hopefully someone sees this
>and can provide one.
>
>thanks,
>Brian
Hi Brian,
Yes, if we can access the XML DOM for the XHTML in the Rich Text Form
Control I can see how to do it using standard XML DOM techniques.
However, I can't see how to access the DOM for the XHTML. Can you
point out where it is exposed?
Thanks.
Your code worked like a charm. I really appreciate you sticking this
problem out! One tiny thing I have noticed, though: When I tried to
edit the template in InfoPath, it would not allow me to save it,
giving me an "xsf file specifies save functionality defined in code,
but code does not define onSave" error. Nevertheless, I am satisfied
with your code, thanks again!
Jeremy
"Joshua Bell [MSFT]" <jo...@online.microsoft.com> wrote in message news:<ukm#Y1fBEH...@TK2MSFTNGP12.phx.gbl>...