Skip to main content
Known Participant
January 12, 2024
Answered

Remove fileicon (Paperclip) When Required Field value 0

  • January 12, 2024
  • 1 reply
  • 795 views

I'm using the following code to upload the file in the PDF Fillable Form 
Current Functionality:
When the User hits the file upload button and uploads the file the value of a field increases by 1 and a file icon created (paperclip icon). on second file upload the value increase 1+ and second paper clip created for that file. 
When Using Clear Button the file counting field clear to 0 but uploaded files (paperclips icons) still there. 

I want to remove the uploaded files icons (paperclips icons) also removed when User Hit the Clear button the Value of the field 0 and all uploaded files removed. 
Screenshot File Uploaded:

 

Screenshot After Clearing the field using Clear Button:

 


As you see the field clear to 0 but fileuploaded icon still there in second screenshot. 

Kindly Update my Following Code to help me. 


var nbComptePJ = this.getField("compteurPJ").value;
if ( nbComptePJ <= "5")
{
	if ( nbComptePJ == "0") {position = [480,119];}
	else if ( nbComptePJ == "1") {position = [500,119];}
	else if ( nbComptePJ == "2") {position = [520,119];}
	else if ( nbComptePJ == "3") {position = [540,119];}
	else if ( nbComptePJ == "4") {position = [560,119];}
	else if ( nbComptePJ == "5") {position = [580,119];}
	var annot = this.addAnnot({
	page: this.pageNum,
	type: "FileAttachment",
	author: "Qamar Farooq",
	contents: "Double Click to check the attachment",
	attachIcon: "Paperclip",
	point: position,
	strokeColor: color.black,
	});
	nbComptePJ++;
	this.getField("compteurPJ").value = nbComptePJ;
}
else
{
	alertPJ = "The maximum limit of 5 attachments."
	app.alert({cMsg: alertPJ, cTitle: "Titre", nIcon: 3});
}

 

This topic has been closed for replies.
Correct answer try67

Try this code:

 

var pageAnnots = this.getAnnots(this.pageNum);
if (pageAnnots!=null) {
	for (var i=pageAnnots.length-1; i>=0; i--) {
		var a = pageAnnots[i];
		if (a.type=="FileAttachment") a.destroy();
	}
}

1 reply

try67
Community Expert
Community Expert
January 12, 2024

You need to locate the annotation you created earlier and then destroy it. If they are the only FileAttachment comments on the page that shouldn't be too difficult. Use getAnnots to get all the comments on the page, then loop the array (from end to start), checking the type property of each comment, and the destroy method to remove it.

Hafiz79Author
Known Participant
January 13, 2024

Thanks for your reply. Can you please update it in my code? I am not clear how to do that. 

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 13, 2024

Try this code:

 

var pageAnnots = this.getAnnots(this.pageNum);
if (pageAnnots!=null) {
	for (var i=pageAnnots.length-1; i>=0; i--) {
		var a = pageAnnots[i];
		if (a.type=="FileAttachment") a.destroy();
	}
}