Allowing tabs in a text area

In addition to controlling the maximum number of characters in a text area, I also want to allow the user to enter tabs. But default, hitting tab would move out of the text area to the next control on the page.

Overriding this behavior can be done by using the onKeyDown event controller so you can:

  1. check if the tab key has been pressed

  2. if it has, insert a tab at the current cursor location

  3. put focus back into the text area


I've extended my little TextAreaTagLib to handle an 'allowTabs' attribute. Now you can allow tabs to be entered just by using allowTabs="true". I've also incorporated the work from the TextField modification so that the number of characters can be limited based on the maxSize constraint on the object.

Sample use:
<g:javascript library=”prototype”/>
<jttext:script />
...
<jttext:textArea object="${new Book()}" name="content" allowTabs="true"/>
<jttext:statusDiv for="content" />

Please note: I've now called the tag lib JTFormTagLib.groovy, and it has both the TextArea and the TextField code in it.

Download here.

Also, I've thought about creating it as a plugin, but it's kind of small to warrant a plugin by itself - what do you think?

Popular posts from this blog

Slow, Buffering, Stuttering Udemy Video

Intellij tip - Joining multiple lines into one

Looking for IT work in Australia? JobReel.com.au!