Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

New lines in rich text boxes

403 views
Skip to first unread message

Jeremy Chamilliard

unread,
Mar 4, 2004, 2:41:39 PM3/4/04
to
Is it possible to get the default contents of a rich text box to
include paragraph breaks? (Example: a mailing address) When I try to
feed the \n char from the jscript, nothing happens...
Thanks

Andrew Watt [MVP - InfoPath]

unread,
Mar 4, 2004, 5:17:55 PM3/4/04
to
On 4 Mar 2004 11:41:39 -0800, jchami...@priorityone.ca (Jeremy
Chamilliard) wrote:

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

Jeremy Chamilliard

unread,
Mar 5, 2004, 8:57:04 AM3/5/04
to
Thanks for your insight Andrew.

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?

Andrew Watt [MVP - InfoPath]

unread,
Mar 5, 2004, 11:15:26 AM3/5/04
to
On 5 Mar 2004 05:57:04 -0800, jchami...@priorityone.ca (Jeremy
Chamilliard) wrote:

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.

Joshua Bell [MSFT]

unread,
Mar 6, 2004, 2:03:26 PM3/6/04
to

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.)


Jeremy Chamilliard

unread,
Mar 8, 2004, 10:08:47 AM3/8/04
to
Joshua,

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

Jeremy Chamilliard

unread,
Mar 8, 2004, 10:17:45 AM3/8/04
to
I appreciate your help Andrew, here is my code,

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

Joshua Bell [MSFT]

unread,
Mar 9, 2004, 12:40:54 PM3/9/04
to
Jeremy Chamilliard wrote:
> 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"

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.


Brian Teutsch [MSFT]

unread,
Mar 9, 2004, 6:21:08 PM3/9/04
to
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

"Jeremy Chamilliard" <jchami...@priorityone.ca> wrote in message
news:f2e98372.04030...@posting.google.com...

Andrew Watt [MVP - InfoPath]

unread,
Mar 10, 2004, 6:28:00 AM3/10/04
to
On Tue, 9 Mar 2004 17:21:08 -0600, "Brian Teutsch [MSFT]"
<bria...@online.microsoft.com> wrote:

>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.

Jeremy Chamilliard

unread,
Mar 10, 2004, 9:15:39 AM3/10/04
to
Joshua,

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>...

0 new messages