logo

Hiding attachments (without noscript tag!)

Don't worry it is not the infamous noscript tag method. We all know about that one by now, don't we!? This is a much cleaner way of doing it. I never liked that method anyway, it seems a bit perverse and uses a "trick" to do something that it was never intended to do. At the end of the day it doesn't really hide the attachment, its details are still visible in the source-code.

Here is how you can do it using Domino's own functionality:

  1. Add a hidden, computed for display field to your form
  2. Call it $V2AttachmentOptions.
  3. Set its value depending on what you want to do.
    • Value "0" to hide any file attachments.
    • Value "1" to show any file attachments.
  4. Remove all those nasty <noscript> tags....
What I usually do is set its value using the following formula:

@If(@IsDocBeingEdited; "1"; "0")

This way we can hide the attachments when the document is being read and show them in edit mode, enabling deletion. If you need to link to the attachments when they are hidden, use a Computed-Text area with a formula similar to:

@If(!@Attachments; @Return(""); "");
"View attachments here:<br>" +
@Implode("<a href=\"" + @Text(@DocumentUniqueID) + "/$file/" + @AttachmentNames + "\">"+@AttachmentNames + "</a>"; "<br>")

Feedback

  1. PROBLEM !!

    This little trick does not seem to work when a Rich-Text field, using the Java applet, exist on the form.

    Moral of the story. Do NOT use those damn Java applets....

    1. The reason why it doesn't work

      Hi, I've found out why it doesn't work when you use a Java-applet to display the RT field. When attaching files combined with the RT field the attachments are not saved as V2-attachments, but are attached to the RT field. That's why it doesn't work. I'm working on a WebQuerySave-agent to remove the attachments from the RT field and reattach them as V2-attachments. This should then bypass the problem.

      Show the rest of this thread

  2. Attachment still shows at the bottom

    I have tried using the <noscript> tag with no hide attributes and the attachment still shows in read mode. I have also used the $V2AttachmentOptions field and the attachment info still appears in edit and read mode. Can you offer any suggestions. I am desperate!

    1. Re: Attachment still shows at the bottom

      The only thing I can think of is that you are using the Java Rich Text Editor, which stores everything in MIME format. When this is the case attachments are no longer V2 and you can't hide them....

      Jake -CodeStore

      Show the rest of this thread

    2. Re: Attachment still shows at the bottom

      I have the same problem here, if i attach a file on a document that has been created via a browser and later attach a file on that same document via the notes client, the second attached file will be displayed on the bottom of the document...

      • avatar
      • Mary
      • Fri 15 Apr 2005

      Attachment shows at the bottom, in notes client

      Hi, I don't get to work, hiding attachments in my notes form. I have added a hidden, computed for display field to my form,called $V2AttachmentOptions,Value "0" and I create a RT field("Anexo"), throught an action, and there isn't another rich text field on the form. When I add an attachment,and save my document, this display the document with duplicate entries for the attachments. i.e: If I add 2 attachments,this display in my doc, in this way: $File: binary.gift $File:exercise.text

      Anexo:binary.gift Anexo:exercise.text And attachments still appears in edit and read mode, at the bottom.

      My action code is:

      Set odbactual = osesion.CurrentDatabase Set ouidoc = owork.CurrentDocument Set odocActual = ouidoc.Document If ouidoc.IsNewDoc Then If odocActual.titulo(0) <> "" Then Call ouidoc.save Else Messagebox "Error",16,"Aviso" Exit Sub End If End If Dim odocNewS As New NotesDocument( odbActual )

      Dato = owork.DialogBox( "Select attachment", True,True, False, False, False,False, "please select one.", odocNewS, True)

      If Dato = False Then Exit Sub filename = odocNewS.Fichero (0) var = odocNewS.Titulo (0) nombreFichero$ = Strrightback(filename,"\") If Not odocActual.HasItem( "Id_Anexo" ) Then odocActual.Id_Anexo= "" odocActual.nombre_Anexo = "" odocActual.tamaño_Anexo = "" odocActual.titulo_Anexo = "" End If Set oitemId = odocActual.GetFirstItem("Id_Anexo" ) If Not (oitemId.Contains(nombreFichero$)) Then If odocActual.HasItem( "Anexo" ) Then Set ver = odocActual.GetFirstItem( "Anexo" ) If ( ver.Type = RICHTEXT ) Then Set ortitem = odocActual.GetFirstItem( "Anexo" ) Else Set ortitem = New NotesRichTextItem( odocActual, "Anexo" ) End If Else Set ortitem = New NotesRichTextItem( odocActual, "Anexo" ) End If

      Set oEmbedded = ortitem.EmbedObject ( EMBED_ATTACHMENT, "", filename ) sizeInBytes = oEmbedded.FileSize If sizeInBytes>1024 Then tamaño = Cstr(Round((sizeInBytes/1024),0))+" KB" Else tamaño = Cstr(sizeInBytes)+" BYTES" End If If var="" Then var = nombreFichero$ End If

      Call oitemId.AppendToTextList(nombreFichero$) Set oitemNombre = odocActual.GetFirstItem( "nombre_Anexo" ) Call oitemNombre.AppendToTextList( nombreFichero$ ) Set oitemTamaño = odocActual.GetFirstItem( "tamaño_Anexo" ) Call oitemTamaño.AppendToTextList( tamaño ) Set oitemTituloAnexos = odocActual.GetFirstItem("titulo_Anexo") Call oitemTituloAnexos.AppendToTextList(var) Call ouidoc.refresh Else Messagebox "there's other attachments with the same name",16,"Aviso" End If

      I have this form, but in html, to display it in web,with the field $V2AttachmentOptions,Value "0", and the action to attach is similar,and hiding attachments works great, in web!!!

      I don't find which is the problem in notes client.Can you offer any suggestions. I am desperate!

      Show the rest of this thread

      • avatar
      • Svetos
      • Fri 17 Apr 2009

      Re: Attachment still shows at the bottom

      Make sure the $V2AttachmentOptions field is set to a text zero - "0" .

      If you miss out the quotes the value is interpreted as a number and hiding doesn't work.

  3. Clean and simple solution

    It works well with the file upload controls. Thank you, contributor. Thanks codestore for great contents.

    • avatar
    • John Clark
    • Wed 5 Dec 2001

    What about Rich Text Fields

    Is there a way to hide attachments that have been 'automatically' put into the 1st rich text fields?

    1. Re: What about Rich Text Fields

      Somebody told me that if you have two Java RT fields on a form and hide the first one the attachment will be hidden with it.

      Jake

      Show the rest of this thread

    • avatar
    • Poindexter
    • Fri 27 Dec 2002

    Another Method

    Here's another method, kudos to Abdul Anwer via Note.net. His method worked for me, whereas none of the others did.

    Create a computed for display field with the following formula:

    "["+@If(@BrowserInfo("BrowserType") = "Netscape"; "<LAYER STYLE=\"display:none\" >";"<NOFRAMES>")+"]"

    Make sure this new field is at the very bottom of the form.

  4. Hide/Show Image

    Great! It worked in my first test!

    But not in my second :( I read that it wont work if you have a RT-Field with Java. My form looks like this:

    One RT-Field (Java) where the users can wright their text with bold, italic or what ever. Great! One fileupload-control to upload a image to the document. And some HTML with <computed value> to show the image.

    If I don't have a RT-Field with Java it works great.(My first test) The image is shown in my HTML-string with the <computed value>. And with the $V2AttachmentOptions field I can delete and replace the image, GREAT!

    But how can I work this out if I want to have the RT-Field with Java? It seems to save the image in that RT-Field and the ugly icon in tables is shown. No image in my HTML-string.

    If I set <div>-tags around the RT-Field the field is hidden and also the ugly icon. But then the users can't wright any text.

    Plz I'm going crazy over here.

    Thanx Richard

    1. Re: Hide/Show Image

      Problem solved!

    • avatar
    • Jeff
    • Thu 28 Apr 2005

    How to give user's delete ability

    My users don't want to see the Domino default attachment display. So I hid them using this method.

    But they do want the delete feature while using this $V2AttachmentOptions method.

    Anyone know how to do that?

    Thanks, -Jeff

      • avatar
      • Jake Howlett
      • Thu 28 Apr 2005

      Re: How to give user's delete ability

      Search for "Attachment Manager"

    • avatar
    • MoonShadow
    • Thu 13 Oct 2005

    $V2AttachmentOptions

    Your the man.

    Whay can't everyone make things this easy !!!!

    Thanks Heaps.

    1. Re: $V2AttachmentOptions

      Can you please help find out how to delete an attachment from a file. what are the functions to be used and if you have any other hints. thank you in advance

      Show the rest of this thread

  5. $V2AttachmentOptions in notes

    I did use the field $V2AttachmentOptions as Text and computed-for-display in my form but I still have the attachment displayed at the bottom of the page. Value of the field is "0". Any idea?

    1. Re: What about Rich Text Fields

      This works fine, and now I have another dilemma. I want to scan my attachment list and only build image tags to display those attachments that are jpg's or gifs. I'm using this formula:

      AttachList := @ReplaceSubstring(@AttachmentNames; " " ;"+" ); Currentview := @ReplaceSubstring(@Subset(@ViewTitle; 1);" ";"+"); AttSuffix := @LowerCase(@Right(@AttachmentNames;3));

      @If(AttSuffix="gif" | AttSuffix="jpg"; "<img src=\"/" +@ReplaceSubstring(@Subset(@DbName; -1);"\\";"/") +"/ContentByCategory/" + @Text(@DocumentUniqueID ) + "/$File/" + AttachList + "\">";"")

      My question: How do I just pull out only those attachment that are jpgs or gifs? i.e. if a doc contains a jpg and a word doc, for example.

      thanks!

        • avatar
        • dan c
        • Wed 21 Aug 2002

        Re: What about Rich Text Fields

        Is this what you want?

        This selects the second attachment and displays it as a thumbnail link if it is a jpg or gif and diplays a text link if it isn't. I don't remember exactly why I have it picking the attachments one at a time, but change the last number after selected file to 1 through however many.

        This is out of a show as html view column, but it works pretty much the same in computed fields.

        I am sure there is a more elegant way to do this.

        --dan SelectedFile:=@Word(@Implode(@AttachmentNames); " ";2); ANames:=@ReplaceSubstring(SelectedFile;" ";"+"); ANames2:=@ReplaceSubstring(SelectedFile;" ";"_"); DBName := @ReplaceSubstring(@ReplaceSubstring(@Subset(@DbName; -1);" ";"+");"\\";"/"); open:="?OpenElement"; view:=@ReplaceSubstring(@ReplaceSubstring(@Subset(@ViewTitle; 1);" ";"+");"\\";"/"); docid:=@Text(@DocumentUniqueID); url:="{<a href=/"+dbname+"/"+view+"/"+docid+"/$FILE/"+ANames+"><img src=/"+dbname+"/"+view+"/"+docid+"/$FILE/"+ANames+" WIDTH=200 Hspace = 20 Vspace=20 border=2 ALT="+ANames2+"></a>}"; url2:="{<br><a href=/"+dbname+"/"+view+"/"+docid+"/$FILE/"+ANames+">" + SelectedFile + "</a><br>}"; @If(SelectedFile = NULL;NULL; @Ends (@LowerCase(SelectedFile) ; "gif" ) ; url; @Ends (@LowerCase(SelectedFile) ; "jpg" ) ; url; url2)

          • avatar
          • Jake Howlett
          • Wed 21 Aug 2002

          Re: What about Rich Text Fields

          Thanks for sharing that with us Dan.

          Just one thing to add. Remember that JPEGs can end in .jpeg as well as .jpg so using @Right(.) is probably the most fool-proof method.

          Jake -webmaster

          1. Re: What about Rich Text Fields

            My solution was to pull out the jpgs using the formula below (it currently only works for .jpg but will also change it to include .gif and jpeg in future):

            attachlist:=@AttachmentNames; tmp := @ReplaceSubstring(attachlist; ".jpg"; ""); TextListWithJPGs := @Trim(@Replace(attachlist; tmp; ""));

            "{<img src=\"/" +@ReplaceSubstring(@Subset(@DbName; -1);"\\";"/") +"/ContentByCategory/" + @Text(@DocumentUniqueID ) + "/$File/" + TextListWithJPGs + "\"><BR>} "

            {}s == []s

            This reply is already 8 levels deep and so replying at this level is disabled.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:



Navigate other articles in the category "Miscellaneous"

« Previous Article Next Article »
Listing search results in groups   Attachments Manager R1.0

About This Article

Author: Jake Howlett
Category: Miscellaneous
Keywords: attachment; hide;

Options

Feedback
Print Friendly

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »