Hi all.
The title says it pretty well. I've bound the "Text" property of a text area to a custom property string in the root container so that strings I pass to the window are displayed in the text area. Is it possible to format a passed-in string in such a way that the text area will render a new line? For example, if I pass in "This is line 1\nThis is line 2" I'd like the text area to render '\n' as a new line.
Have you tried passing an string with HTML formatting?
Basically:
"<HTML>This is line 1<br>This is line 2"
https://docs.inductiveautomation.com/display/DOC81/HTML+in+Vision
Hi Leonardo. Thanks for the reply.
Yes, I tried that. I've also tried some other suggestions online such as using double line breaks (\n\n or \r\n) and using %0D%0A. They're all rendered literally. I've read on the Perspective forums that text areas do this due to security reasons, but at least in Perspective the text areas have a toggle for enabling HTML formatting. Vision text areas do not have this toggle unfortunately.
Maybe you're having issues because what i've sent is actually wrong :: :
Any component on the input tab seems to show the string as a literal, but when you use it on a button or a label, it works like in the video. If you need to use the text area component, maybe the line wrap toggle can help you out.
How are you injecting the \n
into your strings? I've always had them interpreted correctly by text areas if they really are newline characters in the string. (As if loaded from a python string.)
Hi Leonardo.
The text area is necessary because the user is submitting an input string they create which may have multiple lines. Passing in a string with newlines in it may be necessary if I ever want to pre-populate the text area before they edit it.
Hi pturmel.
I have bound "text" property of my text area object, "Body", to the custom property "body" on my root container and I am using a button (just for testing purposes) to set the value of body. The button script is
bodyText = event.source.parent.body
event.source.parent.getComponent('Body').text = bodyText
print(bodyText)
The result is

If I enter the line breaks in the text area itself I can see them in the script variable when I print it, but as for passing linebreaks to text area via a binding I haven't figured that out yet.
Nevermind. I just tried doing it using the text as a system.nav parameter instead of trying to pass it using the button and it did properly render 'This is line1\nThis is line2' as 2 lines in the text box.
Sorry, I should have tried that before posting. Thank you both for the help though!
To clarify, entering 'This is line1\nThis is line2' manually into the root container custom property did not render '\n' properly in the text box (which was bound to the custom property) but passing the same text in to the window using system.nav and param {'body': 'This is line1\nThis is line2'} did work.
Is there no way to get this working without passing through via system.nav.parameter though? I can't do that as I am building something on a template, which is used in a template repeater.
The whole behavior seems super buggy and strange.
I have got a template custom property to store some text (ActionSteps) .
I then tried the following:
-
Bind the Text Area text property to "ActionSteps" directly.
No luck...

-
Type in a string directly to expression binding DOES seem to work.
But that is hardly any use when trying to populate data dynamically.

I really wish these components just supported HTML markup..
OR the components that DO support HTML markup like the "Label" component, would have some sort of useful scrollbars when the text exceeds the component size..