Some dashboard-template-content appears in a different tab (Bug?)

Hello folks,

I'm currently working on a dashboard-project which has some different tabs. In one of those (Controller) I implemented a date/time-rangepicker inside a template-node. Everything is working as it should except some buttons which are getting displayed multiple times in a different tab (Netzwerkkonfiguration [Networkconfiguration]). It's very strange because some of these buttons still have the old label (I've changed the label after some time). I do not understand what triggers that behavior.

How it looks like:

The date/time-rangepicker:

image

The code of the template-node where it has to come from:

<link rel="stylesheet" type="text/css" media="all" href="/daterangepicker/daterangepicker.css" />
<script type="text/javascript" src="/daterangepicker/daterangepicker.js"></script>
<script type="text/javascript" src="/moment/moment.min.js"></script>

<style>
    #button {
        margin-left: 20px;
        order: 2;
        background: transparent;
        border: 0;
        border-radius: 2px;
        box-sizing: border-box;
        font-size: 14px;
        font-style: inherit;
        font-variant: inherit;
        font-weight: 500;
        outline: none;
        overflow: hidden;
        position: relative;
        bottom: 6px;
        text-transform: uppercase;
        transition: box-shadow .4s cubic-bezier(.25,.8,.25,1),background-color .4s cubic-bezier(.25,.8,.25,1);
        user-select: none;
        white-space: nowrap;
        box-shadow: 0 2px 5px 0 rgb(0 0 0 / 26%);
        height: 48px;
        width: 318px;
        display: inline-block;
        letter-spacing: .01em;
    }

    #container {
        display: flex;
        flex-direction: row;
    }

    .card {
        height: 30px;
        width: 318px;
        display: flex;
        flex-direction: row;
    }

    #kt_daterangepicker_2 {
        width: 294px;
    }
</style>

<script>
    $(function(){
        $("#kt_daterangepicker_2").daterangepicker({
        "timePicker": true,
        "timePicker24Hour": true,
        startDate: moment().startOf("hour"),
        endDate: moment().startOf("hour").add(32, "hour"),
        locale: {
            format: "DD/MM/YY HH:mm",
            "applyLabel": "Starten",
            "cancelLabel": "Abbrechen",
        }
        });       
    });

    this.scope.action = function() { 
        if(document.getElementById("kt_daterangepicker_2").value != ""){
            return document.getElementById("kt_daterangepicker_2").value;
        }
    };

    (function(scope) {
        $('#kt_daterangepicker_2').on('apply.daterangepicker', function(ev, picker) {
            scope.startDate = picker.startDate;
            scope.endDate = picker.endDate;
            let payload = {};
            payload.startDate = scope.startDate.format('YYYY-MM-DD');
            payload.endDate = scope.endDate.format('YYYY-MM-DD');
            payload.startTime = scope.startDate.format('HH:mm');
            payload.endTime = scope.endDate.format('HH:mm');
            scope.send({topic:'ok', payload:payload});
        });

        scope.inputfocusout = function(event){
            let payload = {};
            payload.startDate = scope.startDate.format('YYYY-MM-DD');
            payload.endDate = scope.endDate.format('YYYY-MM-DD');
            payload.startTime = scope.startDate.format('HH:mm:ss');
            payload.endTime = scope.endDate.format('HH:mm:ss');
            scope.send({topic:'focusout', payload:payload});
        };
    })(scope);

/*
    <md-card ui-card-size="6x1" class="nr-dashboard-button _md visible">
        <md-button id="button" class="md-raised md-button md-ink-ripple" type="button" ng-click="send({payload:action()})"
            style="padding: 0; margin: 0; width: 318px; height: 48px; position: relative; left: 10px;">OK</md-button>
    </md-card>
*/

</script>


<md-card ui-card-size="12x1" layout="row" layout-align="space-between center" class="nr-dashboard-textinput _md layout-align-space-between-center layout-row visible" style="width:642px; height:48px; margin:0">
    <md-input-container class="md-block md-auto-horizontal-margin flex has-label" style="margin:15,0; width:318">
        <input type="text"  class="form-control form-control-solid" placeholder="Wähle Zeitraum" id="kt_daterangepicker_2" ng-on-focusout="inputfocusout($event)"/>
    </md-input-container>
</md-card>

I hope somebody can help me out.

Thanks in advice.

Justin

It would be helpful if you could upload your flow so someone can look at your settings

flows (8).json (119.5 KB)

Actually there will be some libraries you have to add..

can you take a screen shot of the two tabs and circile the bttons in question?

When taking the screenshots I just realized that these buttons are getting displayed in every tab except "Controller" and getting spawned when changing from Controller into other tabs.

What do you mean with circle the buttons in question?

So I don't have to look thru everything, what tab and what is the label on the template node?

On the 'Netzwerkkonfiguration', the two buttons are specified in the form node. Are they the buttons you are refering to? I only see them on that tab.

Make sure you empty the browsers cache and see it that helps.

It's inside Controller -> "Date picker". These buttons are the buttons from Date picker. They appear when navigating from Controller to another tab.

Clearing the cache didn't help

I haven't seen the data picker. I just realized that in your template node you have:

<link rel="stylesheet" type="text/css" media="all" href="/daterangepicker/daterangepicker.css" />
<script type="text/javascript" src="/daterangepicker/daterangepicker.js"></script>
<script type="text/javascript" src="/moment/moment.min.js"></script>

and I do not have them on my device. Where did you get them from?

Also have you looked at the ui-date-picker` node?

I got them from here. The ui-date-picker is not a date-/time-range-picker. So it doesnt fit in my needs.

So where did you install that code in relation to the node-red folders?

I've installed it in my node-red-static folder. This folder is inside the home next to .node-red

I actually got a new Understanding. I commented out some code sections and got the source of error.
Inside the template node, I created a event listener which checks if the apply button is clicked and sends the current value to the next node.

(function(scope) {
        $('#kt_daterangepicker_2').on('apply.daterangepicker', function(ev, picker) {
            scope.startDate = picker.startDate;
            scope.endDate = picker.endDate;
            let payload = {};
            payload.startDate = scope.startDate.format('YYYY-MM-DD');
            payload.endDate = scope.endDate.format('YYYY-MM-DD');
            payload.startTime = scope.startDate.format('HH:mm');
            payload.endTime = scope.endDate.format('HH:mm');
            scope.send({topic:'ok', payload:payload});
        });

Somewhere inside here the magic is happening. Any idea?

not really, this is outside my knowledge area.
@colin any thoughts?

No, sorry, I don't do much browser side js.

@Steve-Mcl any thoughts about this?

As an aside, in your function node Set timespan on the Controller tab, you send the same msg twice.

You should change the return msg; to return;

1 Like

Thank you for the hint. Unfortunately it is still happening.

I think the daterangepicker itself is causing the problem. I will search for an alternative library.

I tried with these libraries and had no errors:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />

Perhaps this helps. I didn't take your whole project. Just the first statement with the template node.

@knoepsche Thanks for your reply!

I also dont get any errors. But have you tried to change between tabs inside the nodered webinterface? It seems like the daterangepicker is not compatible because the buttons are spawning in every tab. Currently I'm checking the code of the daterangepicker and figgured out that its getting appended to the parentElement, so the body of the site. Changing this parameter to something like a class or id fixes it at least so no buttons getting spawned. But the daterangepicker is appearing way to much in the right this way.