I am trying to validate the combination of 2 fields with Javascript and this is probably a syntax error, but I've tried several variations with no luck. It gives the error on ALL combinations instead of just the two I need or doesn't work at all. I followed these articles an have attempted several things:
https://powerusers.microsoft.com/t5/Power-Apps-Portals/Show-Hide-Section-based-on-Yes-No-toggle-JavaScript/td-p/618918/page/2
https://powerusers.microsoft.com/t5/Power-Apps-Portals/webform-javascript-validation/m-p/694546
https://powerusers.microsoft.com/t5/Power-Apps-Portals/Using-JavaScript-For-Web-Form-Validation-in-Power-Portal/m-p/681344
https://docs.microsoft.com/en-us/powerapps/maker/portals/configure/add-custom-javascript
One version:
if (window.jQuery) {
(function ($) {
webFormClientValidate = function() {
var account = $("#account").val();
var question = $("#findcompany").val();
//need error message if company lookup is blank and answer is 'yes' OR if company lookup not blank and answer is 'no'. Yes/No is a 2 option set, so I've tried both true and false as well as 0 and 1 for the values, but same issue.
if ((account == null && question == false) || (account != null && question == true) ) {
return true
} else {
alert("Incorrect selection. If Company is selected and correct, select Yes. Otherwise if Company is not found and blank, select No.");
return false;
}
};
}(window.jQuery));
}​
also tried this after finding the radio button post:
if (window.jQuery) {
(function ($) {
webFormClientValidate = function() {
var selectedValue = GetRadioSelectedValue($('#findcompany'));
var account = $("#account").val();
if ((account == null && selectedValue == 0) || (account != null && selectedValue == 1) ) {
return true
} else {
alert("Incorrect selection description");
return false;
}
};
}(window.jQuery));
}
GetRadioSelectedValue = function(input) {
if (!!$(input).find("input[type=radio]")) {
var controlName = $(input).find("input[type=radio]").first().attr("name");
if (!!controlName) {
return $("input[name='" + controlName + "']:checked").val();
}
}
return "";
};
Still not working. Please help and thank you.