Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the minimum size of a text box?  RSS feed

 
Raghu Sha
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am using JSF 2 & Richfaces 4

My input text box should accept only 1 character.
<h:inputText id="empid" value="#{details.val}" size="1" />

Set the size as 1, still it showing more size in the screen.
Apart from size =1, any other place to set the size of the text box?
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same as the regular HTML control that the h:inputText control is based on. "maxlength".

Size specifies how many character-widths wide the box should be. These days, it's probably better to do that via CSS.

maxlength specifies how many characters you can enter in the box.
 
Raghu Sha
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

Textbox should accept 1 character. That is handled in maxlength.
But text box size should also having length of 1 character only.
Currently it is showing length as more than 1 character.

How to handle this one.
Please help.
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "size" attribute computes an estimated width, but it is not a very accurate one one any of the systems I've worked on.

A more precise control can be used by adding a CSS width attribute.

For example:


A width of 1 "em" is the width of a single letter "m" using the font that renders the text being input. This will usually be slightly larger than a numeric digit unless you are using a mono-spaced font, which by definition has all characters the same width. Most fonts use the same width for all digits, by the way. The letter "m" is typically the widest character in the font, although in some cases a "w" may be wider.

For best results, study up on the CSS metric options and pick whatever pleases you most.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!