Problem to save value of a select

Hi everyone

I have a select input with 2 customs value and one string value. When I put the value "type" in the "defaults" and that the click on my node, the node editor is empty while when I put in comment the value "type" it is not anymore but the select does not keep the value in memory while the other fields work very well.
Thank you in advance for your help

<script type="text/javascript">
    RED.nodes.registerType('Message',{
        category: 'matrice_svi',
        color: '#A1EEBD',
        defaults: {
            //type: {value:""},
            //static
            condition: {value:""},
            file: {value:""},
            tts:{value:""},
            //complex
            value:{value:""},
            interpretAs:{value:""},
            inputFormat:{value:""},
            format:{value:""},
            fonction:{value:""}
        },
        inputs: 1,
        outputs: 1,
        icon: "icons/icon.svg",
        label: function() {
            return this.name||"Message";
        },
        oneditprepare: function() {
            var static = {
                value: "static",
                label: RED._("node-red:static"),
                hasValue: false
            };
            var complex = {
                value: "complex",
                label: RED._("node-red:complex"),
                hasValue: false
            };
            $("#node-input-type").typedInput({
                type:static,
                types:[static,complex,"str"],
                typeField: "#node-input-typeName"
            })

            $("#node-input-type").on("change", function(e) {
                var val = $("#node-input-type").typedInput('type');
                //static
                console.log(val)
                $(".static").toggle(val === "static");
                $(".complex").toggle(val === "complex");
            });
            $("#node-input-type").change();
        }
    });

</script>

<script type="text/html" data-template-name="Message">

    <div class="form-row">
        <label for="node-input-type"><i class="fa fa-tag"></i>type</label>
        <input type="text" id="node-input-type" placeholder="Chaine de caractère">
        <!--<input type="hidden" id="node-input-typeName">-->
    </div>

    <!-----------------------------Static------------------------------------>
    <div class="static">
        <div class="form-row">
            <label for="node-input-condition"><i class="fa fa-tag"></i>condition</label>
            <input type="text" id="node-input-condition" placeholder="condition">
        </div>
            
        <div class="form-row">
            <label for="node-input-file"><i class="fa fa-tag"></i>file</label>
            <input type="text" id="node-input-file" placeholder="file">
        </div>
        <div class="form-row">
            <label for="node-input-tts"><i class="fa fa-tag"></i>tts</label>
            <input type="text" id="node-input-tts" placeholder="tts">
        </div>
    </div>
    <!------------------------------Complex------------------------------------->
    <div class="complex">
        <div class="form-row">
            <label for="node-input-interpretAs"><i class="fa fa-tag"></i>interpretAs</label>
            <input type="text" id="node-input-interpretAs" placeholder="interpretAs">
        </div>
        <div class="form-row">
            <label for="node-input-value"><i class="fa fa-tag"></i>value</label>
            <input type="text" id="node-input-value" placeholder="value">
        </div>
        <div class="form-row" >
            <label for="node-input-inputFormat"><i class="fa fa-tag"></i>inputFormat</label>
            <input type="text" id="node-input-inputFormat" placeholder="inputFormat">
        </div>

        <div class="form-row">
            <label for="node-input-format"><i class="fa fa-tag"></i>format</label>
            <input type="text" id="node-input-format" placeholder="format">
        </div>
        <div class="form-row">
            <label for="node-input-fonction"><i class="fa fa-tag"></i>fonction</label>
            <input type="text" id="node-input-fonction" placeholder="fonction">
        </div>
    </div>

</script>

if you look at the export of any node-red flow, you will see EVERY node has a type property. It is what tells the core the type of node to instanciate.

So, basically, dont use type as one of your properties since it will be superceded / overwritten by Node-RED core code.

2 Likes

Furthermore - i strongly recommend not to use vague node type names.

using message will undoubtedly cause issues if not now, later for users who happen to install other nodes that will use that name.

Try to make them unique across the node-red platform i.e: riri-message

2 Likes

Please do not use generic names for your node, you are certain to cause name clashes for people who want to use them.

(Sorry Marcus, should have read down the thread first, I didn't see your reply).

2 Likes

Hey! We’re all friends here :smiley:

2 Likes

I renamed the node with another name and after forgetting 2-3 elements it works, thanks for your help

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