Page 1 of 1

struggle with text in textdevice

Posted: Monday 04 November 2024 23:13
by BartSr
I'm struggling with a textdevice which I want to show information on two (2) lines.

command in dzVents

Code: Select all

dz.devices(1642).updateText('line 1'..'\n line 2')
this results in:

Code: Select all

line1 line2

but I expected

Code: Select all

line1
line2
what's wrong?

Re: struggle with text in textdevice

Posted: Tuesday 05 November 2024 0:39
by HvdW
Change it to:

Code: Select all

dz.devices(1642).updateText('line 1\n line 2')
or

Code: Select all

local textSensor = dz.devices(1642)
            if textSensor then
                local text = 'line1'..
                '\n\n line2'  
                textSensor.updateText(text)
             end

Re: struggle with text in textdevice

Posted: Tuesday 05 November 2024 7:55
by waltervl
According Dummy wiki for text sensors: you get multiple lines when adding \r\n to the string

https://www.domoticz.com/wiki/Dummy_for ... ext_sensor

Re: struggle with text in textdevice

Posted: Wednesday 06 November 2024 12:27
by BartSr
The problem is weird.
It apprears that the text-device itself had no problem but it occurs once the same textdevice is placed on floorplan.
textdevice.jpg
textdevice.jpg (16.31 KiB) Viewed 2046 times

Re: struggle with text in textdevice

Posted: Thursday 07 November 2024 12:41
by RonkA
Don't use floorplan (not yet..) but try maybe:

Code: Select all

dz.devices(1642).updateText('line 1<br>line 2')

Re: struggle with text in textdevice

Posted: Thursday 07 November 2024 13:42
by BartSr
@Ronka
thanks for suggestion.
your solution works fine for textdevice but if it's on a floorplan it shows up as:
bug.jpg
bug.jpg (2.35 KiB) Viewed 2015 times
feels like being a bug

Re: struggle with text in textdevice

Posted: Thursday 07 November 2024 13:46
by waltervl
Bug or perhaps intended to not have too much data on the floorplan.

Re: struggle with text in textdevice

Posted: Thursday 07 November 2024 15:47
by BartSr
Walter, I expect 1st: bug. I will report abot it.

Re: struggle with text in textdevice

Posted: Thursday 07 November 2024 23:23
by waltervl
Looking at this part of code in the floorplan it looks like it should work with line breaks.
https://github.com/domoticz/domoticz/bl ... s.js#L1891

Code: Select all

        this.data = item.Data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br />$2');
        if (this.data.indexOf("<br />") != -1) {
            this.hasNewLine = true;

Perhaps look with source code option in a browser if you see the <br /> in html

Re: struggle with text in textdevice

Posted: Friday 08 November 2024 10:16
by waltervl
waltervl wrote: Thursday 07 November 2024 23:23 Looking at this part of code in the floorplan it looks like it should work with line breaks.
https://github.com/domoticz/domoticz/bl ... s.js#L1891

Code: Select all

        this.data = item.Data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br />$2');
I asked AI what this should do and it came up with the following description:
This JavaScript line uses a regular expression to replace newline characters in a string with HTML line break tags (<br />).
Here’s a breakdown of how it works:

Regular Expression: /([^>\r\n]?)(\r\n|\n\r|\r|\n)/g
- ([^>\r\n]?): This captures any character that is not > or a newline character, zero or one time.
- (\r\n|\n\r|\r|\n): This captures any of the newline sequences (\r\n, \n\r, \r, or \n).
The g flag at the end indicates a global search, meaning it will replace all occurrences in the string.

Replacement String: '$1<br />$2'
- $1: Refers to the first captured group (any character not > or a newline).
- <br />: Inserts an HTML line break.
- $2: Refers to the second captured group (the newline sequence).

In essence, this line of code ensures that every newline in the string is replaced with an HTML line break, preserving the newline characters themselves. This is useful for displaying text with line breaks in HTML.

Re: struggle with text in textdevice

Posted: Friday 08 November 2024 11:09
by RonkA
Man.. this is quickly turning in to a rabbit hole..
In HTML (up to HTML 4): use <br>

In HTML 5: <br> is preferred, but <br/> and <br /> is also acceptable

In XHTML: <br /> is preferred. Can also use <br/> or <br></br>

Notes:

<br></br> is not valid in HTML 5, it will be thought of as two line breaks.
XHTML is case sensitive, HTML is not case sensitive.
For backward compatibility, some old browsers would parse XHTML as HTML and fail on <br/> but not <br />
So.. <br /> is the way?!?

Re: struggle with text in textdevice

Posted: Friday 08 November 2024 18:51
by BartSr
sorry, no same result as on yr previous proposel....
commenting using mobile so can't drop screenshot