I have a node that needs to update the help text depending on what it gets back from a http GET request so in the html I have:
oneditprepare: function() {
$.getJSON("myRequest", function(data) {
if (data.includes("thing1")) {
$(".Class1").show();
$(".Class2").hide();
$(".Class3").hide();
} else if (data.includes("thing2")) {
$(".Class1").hide();
$(".Class2").show();
$(".Class3").hide();
} else if (data.includes("thing3")) {
$(".Class1").hide();
$(".Class2").hide();
$(".Class3").show();
} else {
$(".Class1").hide();
$(".Class2").hide();
$(".Class3").hide();
this.warn("couldn't identify which thing");
}
});
}
script type="text/x-red" data-help-name="myNode">
<div class="Class1">
<p>help for thing1</p>
</div>
<div class="Class2">
<p>help for thing2</p>
</div>
<div class="Class3">
<p>help for thing3</p>
</div>
</script>
The other side of the request doesn't matter because that is working.
What is happening is that when I open my node it does what it is supposed to do, hides 2 out of 3 help texts. But then in less then a second it shows all three again.
Something seems to be updating the html again to its original form and I can't figure out how to fix it.
Does anyone know what is happening? And hopefully also how I can fix it?