So...
This might be a really simple thing I am missing...
But I am migrating a node over to typescript.
and I have a need to set a config value as undefined
if its length is <1...
setting this.someConfigValue = undefined
in side oneditsave
if it has no length does not seem to work.
its being rendered as a 0 length string?
am I missing something?
Example:
Printing config inside the JS file -> "apiKeys_firmwareUpdateService":""
Hard to say without seeing the src. Is there a repo on GitHub or somewhere else?
Morning @Steve-Mcl
I think I have narrowed it down.
When I do this:
const runtimeNodeSettings = {
category: 'config',
defaults: {
security_S0_Legacy: {
value: undefined,
required: false
}
},
oneditsave: cleanValues
}
RED.nodes.registerType('zwavejs-runtime', runtimeNodeSettings);
function cleanValues() {
this.security_S0_Legacy = undefined;
}
security_S0_Legacy
is still being set to what's in the text box - an empty string ""
Doing this however:
const runtimeNodeSettings = {
category: 'config',
defaults: {
security_S0_Legacy: {
value: undefined,
required: false
}
},
oneditsave: cleanValues
}
RED.nodes.registerType('zwavejs-runtime', runtimeNodeSettings);
function cleanValues() {
this.security_S0_Legacy = undefined;
$('#node-config-input-security_S0_Legacy').remove(); /* <---- This */
}
It does take affect. I was assuming oneditsave
is after the values being fetched from the inputs,
but seems to be before.
I remove the element to stop it being set to an empty string at the end of the pipeline.
I only need to do this if the string length is < 1 but above was just a demo sketch describing the "problem"
You might be better off disassociating the variable from the form. What I mean by this is instead of giving the element an ID of "node-input-xyz" you could ID the element "my-node-el-xyz".
In doing so, you would need to manually retrieve the value in oneditprepare and store the value in your defaults variable in oneditsave.
Agreed!
My current work around feels tacky
Thanks
system
Closed
13 November 2022 08:19
6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.