限制文本以激发文本区域可用大小
我正在尝试构建一个动态大小的 Spark textArea,它将可能的文本限制为其大小。
例如,文本区域设置为宽度=“300”和高度=“100”。现在,用户应该只能输入或粘贴组件中可见的文本。如果输入更多文本,我不希望 textArea 滚动或换行。
我尝试了各种方法,但没有成功。
非常感谢帮助!
I'm trying to build a dynamically sized spark textArea which limits the possible text to its size.
E.g the textarea is set to width="300" and height="100". Now the user should only be able to enter or paste as much text as can be visible in the component. I don't want the textArea to scroll or linebreak if more text is entered.
I tried all sorts of approaches, but none with success.
Help is highly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,但没有找到完美的解决方案。但我找到了解决这个问题的简单方法。
Spark TextArea 具有 IEditableText 类型的 textDisplay 属性。默认情况下,RichEditableText 组件被分配给此属性。该组件中有一个名为 contentHeight 的属性。我使用此属性来确定文本高度是否超过 textArea 高度。所以我的简单解决方案是这样的:
当然,在应用程序中使用之前需要对其进行微调。但我想尽快发布解决方案:)我将发布所需的确切逻辑。但我认为你也可以自己做...
I encountered the same issue but no perfect solution is found. But I found a simple workaround for this issue.
Spark TextArea has a textDisplay attribute of type IEditableText. by default, a RichEditableText component is assigned to this attribute. There is a property called contentHeight in this component. I used this property to determine if the text height exceeds textArea height. So my simple solution is like this:
Of cause, this needs to be fine tuned before using in an application. But I wanted to post the solution as soon as possible :) I will post exact logic required. But I think you can do it by your own too...
对于 Spark textArea,我在每次更改文本时都使用了它:
while (textArea.textFlow.flowComposer.numLines>textArea.heightInLines)
textArea.text = textArea.text.substr(0,textArea.text.length-1);
for a Spark textArea I used this on each change of text:
while (textArea.textFlow.flowComposer.numLines>textArea.heightInLines)
textArea.text = textArea.text.substr(0,textArea.text.length-1);