cancel
Showing results for 
Search instead for 
Did you mean: 

Reg: Deselect/UnFocus on field

pramod_gopisetty1
Active Contributor
0 Kudos

Hello Guru's,

I have a requirement to restrict the file types when adding attachment in Adobe Interactive Form.

Below is the code I have in Validate Event:

It is setting focus when adding document which is not PDF, but when I correct it and give a valid PDF document the focus is still on the field.

Please help me to remove the focus when I attach a PDF file.

if( this.rawValue == null )

{

}

else{ var fileName = this.rawValue;

var ext = fileName.substr(fileName.lastIndexOf('.')+1);

if(ext == "PDF" || ext == "pdf")

{

}

else

{

app.alert("Please select a valid PDF file");

FilePath.validate.nullTest = "error";

xfa.host.setFocus("InteractiveForm.SubForm.row_3.FilePath");

}

}

Thanks,

Pramod

Accepted Solutions (1)

Accepted Solutions (1)

ali_eshaghibeni
Participant
0 Kudos

hi

it seem there is a problem with java code, i believe when the file is attached to the form the value of field is not changed yet, you can try your code in CHANGE event instead of validate and see how it works.

there is another example of java code that you can fit to your requirement.

    function checkFile(fieldObj)
   
{
       
var FileName  = fieldObj.value;
       
var FileExt = FileName.substr(FileName.lastIndexOf('.')+1);
       
var FileSize = fieldObj.files[0].size;
       
var FileSizeMB = (FileSize/10485760).toFixed(2);

       
if ( (FileExt != "pdf" && FileExt != "doc" && FileExt != "docx") || FileSize>10485760)
       
{
           
var error = "File type : "+ FileExt+"\n\n";
            error
+= "Size: " + FileSizeMB + " MB \n\n";
            error
+= "Please make sure your file is in pdf or doc format and less than 10 MB.\n\n";
            alert
(error);
           
return false;
       
}
       
return true;
   
}

hope this helps,

pramod_gopisetty1
Active Contributor
0 Kudos

Hi Ali, Thanks for the reply. When I have the code in Change Event, the control doesn't even go to the code. I tried keeping app.alert to see if it calls Change event, but in my case it doesn't call it. And the code which you have suggested didn't work. it doesn't even give alert message. Any other ideas? Thanks, Pramod

pramod_gopisetty1
Active Contributor
0 Kudos

This code fixed the issue. Thanks, Pramod if( this.rawValue == null ) { } else{ var fileName = this.rawValue; var ext = fileName.substr(fileName.lastIndexOf('.')+1); if(ext == "PDF" || ext == "pdf") { FilePath.validate.nullTest="disabled"; FilePath.border.edge.color.value="255,255,255"; } else { app.alert("Please select a valid PDF file"); FilePath.validate.nullTest = "error"; } }

Answers (1)

Answers (1)

pramod_gopisetty1
Active Contributor
0 Kudos

Anyone any ideas on how to fix this. Thanks, Pramod