javascriptprocessmaker

If Else if not working correctly


I'm building a form based process in a 3rd party web based platform, initial form is complete and has some fields that are hidden until options via a drop down are selected. The code for this is below and it works.

 //Hide fields until number of banners is selected
$("#CWE_Pull1").hide();
$("#CWE_Pullup2").hide();
$("#CWE_Pullup3").hide();
$("#CWE_Pullup4").hide();


$("#CWE_PullUp").setOnchange( function(newVal, oldVal) {
if (newVal == "1") {
$("#CWE_Pull1").hide();
$("#CWE_Pullup2").hide();
$("#CWE_Pullup3").hide();
$("#CWE_Pullup4").hide();
}
else if (newVal == "2") {
$("#CWE_Pull1").show();
$("#CWE_Pullup2").hide();
$("#CWE_Pullup3").hide();
$("#CWE_Pullup4").hide();
}
else if (newVal == "3") {
$("#CWE_Pull1").show();
$("#CWE_Pullup2").show();
$("#CWE_Pullup3").hide();
$("#CWE_Pullup4").hide();
}
else if (newVal == "4") {
$("#CWE_Pull1").show();
$("#CWE_Pullup2").show();
$("#CWE_Pullup3").show();
$("#CWE_Pullup4").hide();
} else if (newVal == "5") {
$("#CWE_Pull1").show();
$("#CWE_Pullup2").show();
$("#CWE_Pullup3").show();
$("#CWE_Pullup4").show();
}
});

In step 2 the form goes to a different user and I mark the fields to be read only. I can select if the user has Parent, Edit, View or disabled access to fields via the form builder GUI, this is how read only is chosen.

In the debugger for the read only copy I can see the variable is displaying a value as per the picture below so if I try the below If\Else if statement nothing happens.

$("#CWE_Pull1").hide();
$("#CWE_Pullup2").hide();
$("#CWE_Pullup3").hide();
$("#CWE_Pullup4").hide();


if ("#CWE_PullUp" == "2") {
    $("#CWE_Pull1").show();
    $("#CWE_Pullup2").hide();
    $("#CWE_Pullup3").hide();
    $("#CWE_Pullup4").hide();
    }
  else if ("#CWE_PullUp" == "3") {
    $("#CWE_Pull1").show();
    $("#CWE_Pullup2").show();
    $("#CWE_Pullup3").hide();
    $("#CWE_Pullup4").hide();
    }
else if ("#CWE_PullUp" =="4") {
    $("#CWE_Pull1").show();
    $("#CWE_Pullup2").show();
    $("#CWE_Pullup3").show();
    $("#CWE_Pullup4").hide();
    }
else if ("#CWE_PullUp" == "5") {
    $("#CWE_Pull1").show();
    $("#CWE_Pullup2").show();
    $("#CWE_Pullup3").show();
    $("#CWE_Pullup4").show();
    }
;

Variable Image

If I dont have the 4 fields hidden before the if \ else if statement then the fields are all unhidden. I also tried outputting the value of 'CWE_PullUp' to a 2nd variable that wasn't a drop down and using that as the basis for the if \ else if statement but it also did not work.


Solution

  • So this was the solution:

    if ($("#CWE_PullUp").getValue() === "2") {
        $("#CWE_Pull1").show();
    }
    else if ($("#CWE_PullUp").getValue() === "3") {
        $("#CWE_Pull1").show();
        $("#CWE_Pullup2").show();
    }
    else if ($("#CWE_PullUp").getValue() === "4") {
        $("#CWE_Pull1").show();
        $("#CWE_Pullup2").show();
        $("#CWE_Pullup3").show();
    }
    else if ($("#CWE_PullUp").getValue() === "5") {
        $("#CWE_Pull1").show();
        $("#CWE_Pullup2").show();
        $("#CWE_Pullup3").show();
        $("#CWE_Pullup4").show();
    }