Introducing typed inputs in my first custom node ever

Hi folks,

A couple of years ago I developed my first custom node (node-red-contrib-msg-resend), which a couple of numeric inputs on the config screen:

image

Both numeric values can be set dynamically via the input message (msg.resend_interval and msg.resend_max_count). This means that the config screen input contains the default values AND these values can dynamically be overwritten via the input message.

Now I would like to allow the user to choose which msg field he wants to use (e.g. msg.payload.interval), instead of forcing him to use the msg.resend_xxxx fields.

This means I have to use typed inputs like this:

image

But then the interval is specified on the config screen OR in the input message.

So that would break existing flows...
Anybody has an idea how I can accomplish this?

Thanks !!
Bart

Is it just a matter of sequencing the priorities? - use msg. if set; if not, use msg.resend_interval if present; if not, use number.

Assuming you have an input along the lines of:

    <div class="form-row">
        <label for="node-input-interval"><i class="fa fa-file-text-o"></i> Interval</label>
        <input type="text" id="node-input-interval" style="width:70%">
        <input type="hidden" id="node-input-intervalType">
    </div>

Then the logic would be something like:

    if (intervalType === 'msg') {
        await RED.util.evaluateNodeProperty(...
    } else if (msg.hasOwnProperty('resend_interval') {
        ...overridden from msg
    } else if (intervalType === 'number') {
        ...use number entered
    } else {
        ...confused now
    }

For this to work for existing code, I expect you would have to default intervalType to 'number'.

Hi Michael,
Thanks for the assistance! Yes indeed, but in the early days I thought that the config screen contained the default values, which could be overwritten by a control message. But with the typedinput (containing an "msg" and a "num" option), which one of both you want ...

But at first sight your code snippet indeed should work. Will have to mention in my readme that the resend_xxx input message fields are read for legacy reasons ...

Thanks a lot!!
Bart

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.