Hey there
I want to preserve the selected values and therefore whole state of the custom node code below. What is the best way to do that, that e.g. after browser refresh or restart of node-red the selected values are still shown in the UI?
Thank you and have a great weekend.
<script type="text/javascript">
RED.nodes.registerType('sivideo-subscribe-event', {
category: 'SiVideo',
paletteLabel: 'Subscribe Event',
color: '#009999',
defaults: {
name: { value: "" },
server: { value: "", type: "sivideo-server" },
eventTypes: { value: "" }
},
inputs: 0,
outputs: 1,
icon: "font-awesome/fa-rss",
label: function () {
return this.name || "SiVideo Subscribe Event";
},
oneditprepare: function () {
// click event for the button to reload the eventTypes
$("#node-input-eventTypes-button").click(function () {
// make a get request to the server to get the eventTypes
$.get("/getEventTypes", function (data) {
// set the eventTypes to the input
$("#node-input-eventTypes-field").typedInput({
types: [
{
value: "eventTypes",
multiple: "true",
options: data,
}
],
})
});
});
},
// create Listener with the selected eventTypes
oneditsave: function () {
var nodeId = this.id;
// get the selected eventTypes
var eventTypes = $("#node-input-eventTypes-field").typedInput("value");
// create a listener with the selected eventTypes
console.log("sending post request to: /subscribeEvents/" + nodeId + " with eventTypes: " + eventTypes);
$.post("/subscribeEvents/" + nodeId, { eventTypes: eventTypes, nodeId: nodeId }, function (data) {
});
}
}
);
</script>