Hiding a rich text field
Tue 24 Aug 2004, 11:12 AMTweet
by Ben Langhinrichs
There are a number of questions which come up on the forums over and over, and many of them relate to hide-when formulas. I recently wrote a post on Writing better hide-when formulas, which has been very popular and is frequently visited and linked to. I decided to follow that up with a post on hiding a rich text field, since that is also a common question. I pulled this from a few of the many times I've answered this question, including this one back in 1999.
What is the question?
The question is asked different ways, but the common issues are that the hide-when formula appears not to work at all, or it only hides part of the rich text field. Sometimes, attachments are shown when the rest of the rich text field isn't.
What is the issue causing the problem?
In my Rich Text 101 - Hide-when formulas and my earlier Rich Text 101 - Paragraphs, I explain that hide-when formulas are attached to or associated with paragraphs, and that since rich text fields contain embedded paragraphs, those can have hide-when formulas which differ from the form. In particular, it is not uncommon to create a form with a rich text field and a hide-when formula on the field, then later change the hide-when formula. On documents created prior to the change, the first paragraph is likely to reflect the new hide-when formula because it is the "default" paragraph, but subsequent paragraphs are likely to reflect the older formula.
What is the best solution?
Keeping in mind that there are no perfect solutions, there is one good workaround. Put the rich text field inside a section on the form, and add the hide formula to the section. The best way is to collapse the section, and put the hide-when formula on it directly. Now, expand the section and make sure there is no hide-when formula on the field inside the section. This technique will hide attachments and both old and new documents, even if they were created before the change. It also has the advantage that it does not add any hide-when formulas to the rich text inside, so the rich text can be copied elsewhere and not carry long unwanted hide-when formulas.
What are other solutions and why are they not good?
The most common other solution I see is to use computed subforms which contain the rich text field. While this seems like a good idea, Notes has so many problems with rich text fields on subforms that you are likely to cause more problems than you solve. Another solution people suggest is to use a computed field which computes to the real rich text field. This just doesn't work, both because the computed formula will only work when the document is created, and because computed rich text fields can totally mess up the formatting of the rich text, stripping out tables and otherwise causing major changes you don't want.
Copyright © 2004 Genii Software Ltd.
What has been said:
203.1. Stephen Hood (08/25/2004 07:28 AM)
What are the kinds of problems with RT on subforms you are aware of? Currently have an app using such an approach and would like to know if I'm walking into problems down the road..Currently the RT's are all inside sections and the subform is placed inside a table on the main form.
Thanks for the tip.
I had been avoiding the hiding of RT because of these issues but I think I'm covered now because of the way it's already structured. Now if there was a way of determining a RT is blank from a formula...
203.2. Michael Woehrer (28.08.2004 11:05)
Interesting blog entry...
I don't know if it was already mentioned here in this Blog, but another question which comes up on many forum is: "How to prohibit editing rich text fields".
I know 3 workarounds to realize this:
1) Using the entering event, e.g. uidoc.gotofield("Subject")
2) Using a subform
3) Using a controlled access section
I preferred (1) so far, although it is not perfect and imho a stinky workaround.
203.3. Esmond (01/06/2005 08:28 AM)
Good Tip Ben, Thanks alot!
One thing I picked up through some experimentation... The section's hide-when formula seems to only apply to the RT field it contains, If the section is [b]collapsed[/b] when the form is saved. So if you save the form with the section expanded, the RT field will show no matter what. Similarly, setting a section to autoexpand will also defeat the section's hide-when.
203.4. Andre Guirard (06/05/2006 06:25 AM)
If you use a controlled access section with a hidden header line, you can set the section to auto-open for editors and auto-close for non-editors. Then, write a CFD section editor formula that decides who may edit the section, which uses @UserName as its return value if the rich text should be visible. E.g. to hide when Status = "Approved":
@If(Status != "Approved"; @Username; "-nobody-")
203.5. Ben Langhinrichs (06/05/2006 06:38 AM)
Andre - That sounds like a good plan. I'll give that a try as well.
203.6. Trapti (03/28/2007 12:29 AM)
Thats a useful and indepth information about hidewhence on Rich text fields
203.7. Prem (02/21/2008 01:54 PM)
I tried all the options, but it didn't work as expected. I display rtf and label based on radio button selection. The only problem I'm facing is, if I attach a document to rtf and decide to select some other option, even then label part disappears. The hide when formula is as follows
Business != "Option1" & rtffield = "".
But when the document is saved, then the label part works as per formula. Any means of knowing if rtf is blank or not without saving.
203.8. Sreekanth (05/21/2008 10:06 AM)
Ben.. its very good information about Hiding RT .....gr8
203.9. Dan G (09/23/2008 09:42 AM)
Thanks Ben! Works like a champ. (your former associate @JDRP 96)
203.10. Philippe Duvivier (11/05/2009 15:37)
I tried all the options suggested here, which are good workaround, but found another way which also seems to work and is somewhat more simple: I have put the RTF field in a 2 rows table with the options "Show only one row at a time" and "Switch rows programmatically". So you can show either an empty row or the row containing the RTF field. The only restriction is that, as the RTF is in a table, the Paragraph Styles cannot be used (which is another bizarre and annoying restriction of RTF fields).
203.11. venkat (01/18/2010 05:21 AM)
Hi i am new to lotus notes. Can you please explain how to restrict editing the rich text field using subform as mentioned above. Also it should show the attachments in the rich text field.