If a student wants to include a larger amount of text on a screen, I have been telling them to use Text Area in order to limit the amount showing and allow the user to scroll to read. However, when the app is shared, users are still able to type in the text area and change the text as if it was an Input Text. Does anyone have a solution for this?
Hi @echappell,
Text Input and Text Area are both intended as inputs, like fields in a form.
It sounds like thatâs not what youâre looking for - instead, you just want text to appear on the screen, without allowing the user to edit the text, right?
If thatâs the case, the design element youâre looking for is âLabelâ. Students can type as much as they want and resize the box.
?Thank you for your help! Does the label allow for any amount of text (i.e. If it excedes the size of the label, it will allow the user to scroll through it.), or does the text just have to get smaller with more text?
Elizabeth A. Chappell
Computer Science & PLTW
Coach FLL Robotics Team
Groton Middle School
Hi Elizabeth,
You can also use the text area (instead of Label) to limit text and have a scroll bar as you have been doing! Your students just have to do one more step to make the text area âread onlyâ so users cannot write in that space. In Design mode, they can click on the text box, then scroll down in the workspace. They will see the âread onlyâ checkbox there, and can toggle it on or off depending on how they want the user to interact.
?Oh, thatâs perfect! Thank you!
Elizabeth A. Chappell
Computer Science & PLTW
Coach FLL Robotics Team
Groton Middle School
Ooh, nice. I didnât know that one.
This is great, but I want horizontal scrolling too! How would that be accomplished?
I donât think that is possible since the text automatically wraps around.
If you for some reason wanted just horizontal scrolling, you can use this:
setStyle("textareaId","white-space: pre; overflow-wrap: normal;");
This gives me the horizontal scroll bar. Thank you. However when scrolling right, the content of the textarea is blanked out (except the first line).
Hi @kock,
Can you please include a link to the project so we can look at what might be causing this isssue?
Thanks,
Michael K.
Thatâs weird. If you posted the link to the project it may help.
I suppose it has something to do with the white-space property in the setStyle()
, but I havenât used that style property in the past.
If you want to perform more research I suggest going to this StackOverflow question and look for the before-mentioned keyword white-space.
@letti42 has what I think is the right approach. I use textLabel() to create almost all of my elements and then use setParent() and setStyle() to make them look however I want.
something like this:
textLabel("box","");
setStyle("box",
"overflow:auto;" +
"position:absolute;" +
"top:0; left:0; right:0; bottom:0;" +
"padding:0; margin:0;"
);
textLabel("stuff","?");
setStyle("stuff",
"height:600px; width:436px;" +
"background:url(https://upload.wikimedia.org/wikipedia/en/b/bb/General_Iroh.jpg);"
);
setParent("stuff","box");