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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Form Attachment mandat...
Power Pages
Answered

Form Attachment mandatory depending on field

(0) ShareShare
ReportReport
Posted on by 74

Hi,

I need to make the file attachment mandatory depending on a dropdown option.

 

I have made this for other fields by using the validators (similar to this https://powerusers.microsoft.com/t5/Power-Apps-Portals/Make-field-required-in-Portal-based-on-value-selected-in-another/td-p/1253064)

However I can't quite do it with the file attachment.

 

Is it possible to make a verification Portal side only?

Categories:
I have the same question (0)
  • Verified answer
    T1ago Profile Picture
    74 on at

    Managed to figure it out, using the validators. For anyone that might need it:

    var fileRequired = function(fieldName) {
     try {
     if ($("#" + fieldName) != undefined) {
     $("#" + fieldName).prop('required', true);
     $("#" + fieldName).closest(".control").prev().addClass("required");
    
     // Create new validator
     var Requiredvalidator = document.createElement('span');
     Requiredvalidator.style.display = "none";
     Requiredvalidator.id = fieldName + "Validator";
     Requiredvalidator.controltovalidate = fieldName;
     
     Requiredvalidator.errormessage = "<a href='#" + fieldName + "'> File is mandatory";
    
     
     Requiredvalidator.initialvalue = "";
     Requiredvalidator.evaluationfunction = function() {
     var inputFile = $('#AttachFile').val();
     if (inputFile == "") {
     return false;
     } else {
     return true;
     }
     };
    
     // Add the new validator to the page validators array:
     Page_Validators.push(Requiredvalidator);
     }
     } catch (error) {
     errorHandler(error);
     }
     }
    
     var fileNotRequired = function(fieldName) {
     try {
     if ($("#" + fieldName) != undefined) {
     $("#" + fieldName).closest(".control").prev().removeClass("required");
     $("#" + fieldName).prop('required', false);
    
     for (i = 0; i < Page_Validators.length; i++) {
     if (Page_Validators[i].id == fieldName + "Validator") {
     Page_Validators.splice(i);
     }
     }
     }
     } catch (error) {
     errorHandler(error);
     }
     }

     

    And then use when needed (fieldName is <input> ID of the file upload):

    fileNotRequired("AttachFile");

    fileRequired("AttachFile");

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
Fubar Profile Picture

Fubar 51 Super User 2025 Season 2

#2
Jerald Felix Profile Picture

Jerald Felix 25

#2
Lucas001 Profile Picture

Lucas001 25 Super User 2025 Season 2

Last 30 days Overall leaderboard