Tip: Validating a rich text field in Lotus Notes

This tip offers three ways that you can validate rich text input fields in Lotus Notes.

Share:

Manish K. Prasad, Software Engineer, IBM

Manish K. Prasad is a Software Engineer with the Groupware team in IBM India. His primary area of interest lies in the security features of Lotus Notes applications.



20 December 2005

Also available in Russian Japanese

This tip describes three quick methods for validating a rich text field in Lotus Notes. The first method validates a text field in which any text (including a single space character) is an acceptable input. The second method validates a field in which at least some non-space text is required. The third method validates a field that may contain no text, but may contain an attachment, embedded object, or link. We assume that you have some experience developing applications using Domino Designer and LotusScript.

Method 1

In the first method, if the field contains any input (even only a single space character), then it can pass the validation. This validation uses the Querysave event of the form that contains the field. The following LotusScript sample code performs this validation:

Sub Querysave(Source As Notesuidocument, Continue As Variant)
            If ( Source.FieldGetText( "rtfield" ) = "" ) Then
		Messagebox( "Please enter some text." )
		Call Source.GotoField( "rtfield" )
		Continue = False
	End If
End Sub

The code checks for any character in the field rtfield. If the field contains input (even if it consists solely of one or more space characters), then validation succeeds. If the field is empty, then the code returns an error message, and doesn’t save the document (by setting Continue to False).

Method 2

In the second method, the rich text field must contain at least one non-space character (in other words, an input consisting entirely of one or more spaces is not allowed). This check also uses the Querysave event of the form:

Sub Querysave(Source As Notesuidocument, Continue As Variant)
	
	Dim rtitem As NotesRichTextItem
	Set doc = Source.Document
	Set rtitem = doc.GetFirstItem( "rtfield" )
	Dim text As String
	
	text$ = Source.FieldGetText("rtfield")
	trimmed$ = Trim(text)
            
            if ( trimmed$ = "") Then
		Msgbox "Please enter some text."
		Continue = False
		source.GotoField("rtfield")
		source.Refresh(True)
	Else
		Continue = True
		
	End If
End Sub

Method 3

Our third method validates a rich text field in which an input consisting solely of an attachment, embedded object, or link is allowed, even if it includes no accompanying text. Once again, we use the Querysave event of the form containing the field:

Sub Querysave(Source As Notesuidocument, Continue As Variant)
	
	Dim rtitem As NotesRichTextItem
	Set doc = Source.Document
	Set rtitem = doc.GetFirstItem( "rtfield" )
	Dim text As String
	
	text$ = Source.FieldGetText("rtfield")
	trimmed$ = Trim(text)
	
	If(doc.Hasembedded)  Then
		Continue = True
				
	Elseif ( trimmed$ = "") Then
		Msgbox "Please enter some text."
		Continue = False
		source.GotoField("rtfield")
		source.Refresh(True)
	Else
		Continue = True
	
            End If
End Sub

This code will work if there is an attachment anywhere in the document, even if it's not in the field that is being validated.

Resources

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into IBM collaboration and social software on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Lotus
ArticleID=100395
ArticleTitle=Tip: Validating a rich text field in Lotus Notes
publish-date=12202005