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-...)
However I can't quite do it with the file attachment.
Is it possible to make a verification Portal side only?
Solved! Go to Solution.
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):
fileRequired("AttachFile");
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):
fileRequired("AttachFile");
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
User | Count |
---|---|
7 | |
3 | |
2 | |
1 | |
1 |