1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Fix inject now button unable to send empty props

This commit is contained in:
Nick O'Leary 2021-07-28 10:59:16 +01:00
parent 6364e00202
commit f8571023f6
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 24 additions and 14 deletions

View File

@ -193,7 +193,7 @@
} }
/** Perform inject, optionally sending a custom msg (refactored for re-use in the form inject button)*/ /** Perform inject, optionally sending a custom msg (refactored for re-use in the form inject button)*/
function doInject(node, customMsg) { function doInject(node, customMsg) {
var label = node._def.label.call(node); var label = node._def.label.call(node,customMsg?customMsg.__user_inject_props__:undefined);
if (label.length > 30) { if (label.length > 30) {
label = label.substring(0, 50) + "..."; label = label.substring(0, 50) + "...";
} }
@ -201,7 +201,8 @@
$.ajax({ $.ajax({
url: "inject/" + node.id, url: "inject/" + node.id,
type: "POST", type: "POST",
data: customMsg, data: JSON.stringify(customMsg||{}),
contentType: "application/json; charset=utf-8",
success: function (resp) { success: function (resp) {
RED.notify(node._("inject.success", { label: label }), { type: "success", id: "inject", timeout: 2000 }); RED.notify(node._("inject.success", { label: label }), { type: "success", id: "inject", timeout: 2000 });
}, },
@ -291,7 +292,7 @@
} }
return lab; return lab;
}, },
label: function() { label: function(customProps) {
var suffix = ""; var suffix = "";
// if fire once then add small indication // if fire once then add small indication
if (this.once) { if (this.once) {
@ -304,11 +305,23 @@
if (this.name) { if (this.name) {
return this.name+suffix; return this.name+suffix;
} }
var payload = "";
var payload = this.payload || ""; var payloadType = "str";
var payloadType = this.payloadType || "str"; var topic = "";
var topic = this.topic || ""; if (customProps) {
for (var i=0;i<customProps.length;i++) {
if (customProps[i].p === "payload") {
payload = customProps[i].v;
payloadType = customProps[i].vt;
} else if (customProps[i].p === "topic") {
topic = customProps[i].v;
}
}
} else {
payload = this.payload || "";
payloadType = this.payloadType || "str";
topic = this.topic || "";
}
if (payloadType === "string" || if (payloadType === "string" ||
payloadType === "str" || payloadType === "str" ||
payloadType === "num" || payloadType === "num" ||
@ -496,11 +509,8 @@
label: node._("inject.injectNow"), label: node._("inject.injectNow"),
click: function(e) { click: function(e) {
var items = eList.editableList('items'); var items = eList.editableList('items');
var result = getProps(items); var props = getProps(items);
var m = {__user_inject_props__: []}; var m = {__user_inject_props__: props.props};
if (result && result.props && result.props.length) {
m.__user_inject_props__ = result.props;
}
doInject(node, m); doInject(node, m);
} }
} }

View File

@ -101,7 +101,7 @@ module.exports = function(RED) {
this.on("input", function(msg, send, done) { this.on("input", function(msg, send, done) {
var errors = []; var errors = [];
var props = this.props; var props = this.props;
if(msg.__user_inject_props__ && Array.isArray(msg.__user_inject_props__)) { if (msg.__user_inject_props__ && Array.isArray(msg.__user_inject_props__)) {
props = msg.__user_inject_props__; props = msg.__user_inject_props__;
} }
delete msg.__user_inject_props__; delete msg.__user_inject_props__;