Validating rich text

Validating rich text

From "Rich text programmability for Notes R5 applications" by Andre Guirard, who works from Lotus Development's ISV Technical Consulting group, which originally appeared in the May/June 2000 edition of The View


Notes developers have long had to work around the problem that, in Notes, there is no way to make sure that the user enters a value in a rich text field before saving a document. There are workarounds for specific kinds of validations, but until R5, there hasn't been a general-purpose way to validate rich text field contents.

With R5, it's possible to write a Querysave event that reads the current value of the rich text field. To do this, you have to refresh the form using the NotesUIDocument.Refresh method with an argument of True, as the code below does. This code, created as an example, doesn't actually do any validation; it just displays the text it reads from the rich text field.

Sub Querysave(Source As Notesuidocument, Continue As Variant)
	   Dim ws As New notesuiworkspace
	   Dim uidoc As notesuidocument
	   Dim doc As NotesDocument
	   Dim rtf As Variant
	   Set uidoc = ws.CurrentDocument
	   uidoc.refresh True
	   Set doc = uidoc.Document
	   Set rtf = doc.GetFirstItem("Body")
	   Messagebox debugstr(rtf.text)
End Sub

The debugstr function in this code takes any value and returns a text description of it in a message box. It's not part of the LotusScript language; it's a function the author wrote that can be pasted in whenever one needs to display a value for debugging purposes.

You can try this yourself in the sample database available at The View's Web site: http://www.eview.com/eview/view.nsf/2d0e694750acb0ae8525668000517be3/f40ef674a562b18c852568d30057eee4?OpenDocument

Select Create-Validate Rich Text. Enter some values in the table that opens in the Validate Rich Text document.

When you use the Text property or the GetFormattedText method of a NotesRichTextItem, tables are presented as columns of text separated by tabs. So there's a "tab" character (in LotusScript, Chr$(9)) between each column, and the "newline" sequence, carriage return and line feed (Chr$(13) and Chr$(10)), at the end of each row.

This can get ambiguous if the person editing the document enters tabs or newlines in the table cells. If you were trying to validate the table contents and you looked for the "newline" sequence to spot the end of a row, then "2030" would look like two different rows to you. So you might not be able to tell exactly how the table is formatted. But for validation purposes, you don't care -- just reject any input that doesn't match what you expect.

This was first published in May 2000

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.