web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / restrict file input wi...
Power Pages
Unanswered

restrict file input with javascript

(0) ShareShare
ReportReport
Posted on by 43
I'm trying to restrict a file input on my power pages to just word documents. The JavaScript I use gives an alert when it is not a word document but still add the file.  The preventdefault has no effect on the file upload. is their a way to prevent the file from being attach anyway.
 
var LimitFileUpload = function(fieldName, fileEvent){
    try{
        const allowedExtensions = ['doc', 'docx'];
 
const fileInput = document.getElementById(fieldName);
 
   const file = fileEvent.target.files[0];
  const fileExtension = file.name.split('.').pop().toLowerCase();
 
  if (!allowedExtensions.includes(fileExtension)) {
    alert('Invalid file type. Only word documents are allowed.');
    fileEvent.target.value = ''; // Clear the file input
    fileEvent.preventDefault();
    return false;
  }
    }
    catch(error)
    {
        errorHandler(error);
    }
}
 
 
Categories:
I have the same question (0)
  • Suggested answer
    Fubar Profile Picture
    8,319 Super User 2025 Season 2 on at
    restrict file input with javascript
    What type of file upload are you using? (Notes attachment, or File field)
     
    If using Notes you should be able to set the Mime types that are accepted - if not exposed in the Designer use the Power Pages Management app (I have had issues in the Designer where the mime type option doesn't show sometimes). Also if using notes there can be multiple places depending on how it is being implemented e.g. basic form has a general Notes section, but if using a Metadata record for Notes has areas under the Create & Edit dialogs.
  • knparksnyc Profile Picture
    43 on at
    restrict file input with javascript
     
    Thanks for reply. I have an input file with chose file button that opens a dialog to choose a file, not using notes:
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 66

#2
Fubar Profile Picture

Fubar 47 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard