Skip to main content

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

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

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.

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

All information submitted is secure.

  • Close [x]

Tip: Validating a rich text field in Lotus Notes

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.

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

Date:  20 Dec 2005
Level:  Intermediate
Also available in:   Russian  Japanese

Activity:  15707 views
Comments:  

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

About the author

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.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


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. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

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.

(Must be between 3 – 31 characters.)

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

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

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
author1-email=manprasa@in.ibm.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.

Special offers