I can change payload type run time. Payload type always is "str" when i open properties again.
HTML
<label for="node-input-payload"> payload</label>
<input type="text" id="node-input-payload" style="width:200px;">
<input type="hidden" id="node-input-payload-type" style="width:200px;">
<script type="text/javascript">
<script type="text/javascript">
RED.nodes.registerType('iiotgw-dev in',{
category: 'JinYi Studio',
color:"#c6dbef",
defaults: {
name: { value:"" },
pin: { value:"", required:true, validate:RED.validators.number() },
read: { value:false },
user: { value:false },
payload: { validate: RED.validators.typedInput("propertyType") },
edge: { value:1}
},
inputs:1,
outputs:1,
icon: "rpi.png",
label: function() {
return this.name || 'GPIO'+this.pin ;
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
outputLabels: function() { return 'GPIO'+this.pin; },
paletteLabel: "Dev in",
oneditprepare: function() {
var setstate1 = function () {
if ($('#node-input-user').is(":checked")) {
$("#node-set-payload").show();
} else {
$("#node-set-payload").hide();
}
};
var setstate = function () {
var n1 = Number($("#node-input-edge").val());
// alert("val="+n1);
if (n1===1) {
$("#node-set-user").hide();
} else {
$("#node-set-user").show();
}
setstate1();
};
$("#node-input-edge").change(function () { setstate(); });
$("#node-input-user").change(function () { setstate1(); });
setstate();
$("#node-input-payload").typedInput({
type:"str",
types:["str","num","bool"],
typeField: "#node-input-payload-type"
});
}
});
</script>