Hey hey,
Been searching the forum but havent found the answer I was searching for. Appologies in advance if it is in here some where but havent seen it.
I want to generate a custom dropdown box from an existing object
Im using this in my .html document for node creation but get an empty drop down list.
In fact when debugging this thing I dont even think it executes it.
Do I need to include this in a function somewhere else ?
<div class="form-row">
<label for="node-input-unit"><i class="fa fa-tag"></i>unit</label>
<select id="node-input-unit" style="width:60%; margin-right:5px;">
<!-- fetch units from unit class -->
<script>
var Unit = require('./unit_class') ;
//make new measurement on creation to work with.
var unit = new Unit();
Object.keys(unit.property.volume_flow_rate).foreach(key => {
return '<option value="' + unit.property.volume_flow_rate.key + '">' + unit.property.volume_flow_rate.name + '</option>';
});
</script>
ok gotcha, how would this look like then? document.print( HTML code)? and loop over it where needed?
update : Tried this without succes
oneditprepare: function() {
$("#node-input-smooth_method").change( function() {
var a = $("#node-input-smooth_method").val();
if ((a === "high") || ( a === "low" )) {
$("#node-over").html("with a smoothing factor of ");
$("#node-over2").html("");
//$("#row-input-reduce").hide();
}
else {
$("#node-over").html("over the most recent ");
$("#node-over2").html(" values");
//$("#row-input-reduce").show();
}
});
$("#node-input-smooth_method").change();
if ($("#node-input-round").val() === "true") {
$("#node-input-round").val(0);
}
console.log("test " + Object.keys(unit.property.volume_flow_rate).length);
for (let i = 0; i < Object.keys(unit.property.volume_flow_rate).length; i++) {
let value = unit.property.volume_flow_rate.key;
let text = unit.property.volume_flow_rate.name;
$("#node-input-unit").append(
$("<option></option>").attr("value", value).text(text) //For every element in the select tag append appropriate value and text ( <option value="#">#</option> )
);
}
}
Yeah was ahead of your second suggestion. Thats clear to me...
Just the require thing needs fixing now I think ( I edited my post for the code Im using)
Im trying to import the class object that I wrote because thats filled with my dropdown list items. Or is that not possible?
Sorry but the creating resources guide is pretty vague about how and where to apply it.
I have created a folder called "resources" under my main folder which is called " node-red-node-measurement"
I have tried adding the "url" which is a bit counter intuitive because it refers to building the url putting resource first and then the main folder name and then my js file. Having done that where do I add this ?
When loading resources in the editor, the node must use relative URLs rather than absolute URLs. This allows the browser to resolve the URL relative to the editor URL and removes the need for the node to know anything about how its root paths are configured.
Using the above example, the following HTML can be used to load those resources in the editor:
Node red log says " started flows" however when I load the localhost page it doesnt get past loading the specific node and completely hangs at that node.
I have done exactly what you described adding
in front of the code.
Do you happen to have a working example somewhere that I can see which uses this kind of file and a class which I can use further in the code?