mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Fix inject now button unable to send empty props
This commit is contained in:
		@@ -193,7 +193,7 @@
 | 
			
		||||
    }
 | 
			
		||||
    /** Perform inject, optionally sending a custom msg (refactored for re-use in the form inject button)*/
 | 
			
		||||
    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) {
 | 
			
		||||
            label = label.substring(0, 50) + "...";
 | 
			
		||||
        }
 | 
			
		||||
@@ -201,7 +201,8 @@
 | 
			
		||||
        $.ajax({
 | 
			
		||||
            url: "inject/" + node.id,
 | 
			
		||||
            type: "POST",
 | 
			
		||||
            data: customMsg,
 | 
			
		||||
            data: JSON.stringify(customMsg||{}),
 | 
			
		||||
            contentType: "application/json; charset=utf-8",
 | 
			
		||||
            success: function (resp) {
 | 
			
		||||
                RED.notify(node._("inject.success", { label: label }), { type: "success", id: "inject", timeout: 2000 });
 | 
			
		||||
            },
 | 
			
		||||
@@ -291,7 +292,7 @@
 | 
			
		||||
            }
 | 
			
		||||
            return lab;
 | 
			
		||||
        },
 | 
			
		||||
        label: function() {
 | 
			
		||||
        label: function(customProps) {
 | 
			
		||||
            var suffix = "";
 | 
			
		||||
            // if fire once then add small indication
 | 
			
		||||
            if (this.once) {
 | 
			
		||||
@@ -304,11 +305,23 @@
 | 
			
		||||
            if (this.name) {
 | 
			
		||||
                return this.name+suffix;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var payload = this.payload || "";
 | 
			
		||||
            var payloadType = this.payloadType || "str";
 | 
			
		||||
            var topic = this.topic || "";
 | 
			
		||||
 | 
			
		||||
            var payload = "";
 | 
			
		||||
            var payloadType = "str";
 | 
			
		||||
            var 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" ||
 | 
			
		||||
                    payloadType === "str" ||
 | 
			
		||||
                    payloadType === "num" ||
 | 
			
		||||
@@ -496,11 +509,8 @@
 | 
			
		||||
                        label: node._("inject.injectNow"),
 | 
			
		||||
                        click: function(e) {
 | 
			
		||||
                            var items = eList.editableList('items');
 | 
			
		||||
                            var result = getProps(items);
 | 
			
		||||
                            var m = {__user_inject_props__: []};
 | 
			
		||||
                            if (result && result.props && result.props.length) {
 | 
			
		||||
                                m.__user_inject_props__ = result.props;
 | 
			
		||||
                            }
 | 
			
		||||
                            var props = getProps(items);
 | 
			
		||||
                            var m = {__user_inject_props__: props.props};
 | 
			
		||||
                            doInject(node, m);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 
 | 
			
		||||
@@ -101,7 +101,7 @@ module.exports = function(RED) {
 | 
			
		||||
        this.on("input", function(msg, send, done) {
 | 
			
		||||
            var errors = [];
 | 
			
		||||
            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__;
 | 
			
		||||
            }
 | 
			
		||||
            delete msg.__user_inject_props__;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user