Control how attachments are removed

Jake Howlett, 22 January 2001

Category: Forms; Keywords: attachment file remove detach

In a previous article I talked about using a combination of checkboxes and a WebQuerySave agent to produce an alternative method of removing attachments from a document. Thus, getting rid of the horrible check-boxes that domino automatically generates:

Image

Whilst that method worked fairly well, I have since learnt of a much easier/better/quicker way to do this.

All you need to do is create your own set of check-boxes that all share the same name: %%Detach.

Easiest way to do this is to use a Computed-Text area (you can't use a field as they don't allow the % character in the name). The formula should be along the lines of:

@If(!@Attachments; @Return(""); "");
@If(@IsDocBeingEdited;
"<p>Remove attachments here:<br>" +
@Implode("<input type=\"checkbox\" name=\"%%Detach\" value=\""+@AttachmentNames+"\">"+@AttachmentNames; "<br>");
"<p>View attachments here:<br>" +
@Implode("<a href=\"" + @Text(@DocumentUniqueID) + "/$file/" + @AttachmentNames + "\">"+@AttachmentNames + "</a>"; "<br>"))

What does this do? First thing is to see if there are any attachments on the document. If not then it just returns an empty string (""). Otherwise, it checks if the document is in edit mode. If so, it creates a delete checkbox for each attachment with a value the same as the file's name. If the document is being read it simply creates a set of links that the user can use to open or save the file from.

Now, when the document is submitted, domino takes control of the deletion of all the files that you selected automatically. Isn't it a clever little thing...

Here is an example of this method being used in a database available for download here. Firstly in read mode:

Image

and in edit mode:

Image

How you make it look and where you place the HTML is totally down to you. No longer do you have to suffer the awful way Iris does it ;-) The last thing to do is to hide the "Iris" part. You could use the <noscript> method, but I prefer this one as it is a lot cleaner.