TextBox with pre-filled suggestion

217 views
Skip to first unread message

dcheeky77

unread,
Dec 4, 2012, 5:35:58 PM12/4/12
to google-we...@googlegroups.com
Hello!

I need to use a TextBox to enter some data, but the label which explains the field's purpose must be of the kind inside the TextBox itself, which disappears when the user clicks on the field (I hope I've let you understand what I'm talking about ;) )
I'm using GWT 2.4: is there any such component or a common method to achieve the result?

Since I also need to customize the look of the TextBox (rounded corners), I was thinking of implementing my own TextBox, but should it extend Composite? Or is there some other way for "basic" components?

Thank you very much for your help!

dcheeky77

unread,
Dec 5, 2012, 3:33:35 AM12/5/12
to google-we...@googlegroups.com
Wow, thank you very much, I'll definitely give it a try!!!


On Wednesday, December 5, 2012 8:04:33 AM UTC+1, Igor Knyazev wrote:
You can use HTML 5 <input> "placeholder" attribute to achive that.

TextBox textBox = new TextBox();
textBox.getElement().setAttribute("placeholder", "some text");

check browser support of this attribute here http://www.w3schools.com/html5/att_input_placeholder.asp

For rounded borders just add styleName to TextBox with border-radius property

dcheeky77

unread,
Dec 5, 2012, 5:27:25 AM12/5/12
to google-we...@googlegroups.com
I confirm that both solutions worked!!
Thank you very much!

Drew Spencer

unread,
Dec 6, 2012, 7:56:33 AM12/6/12
to google-we...@googlegroups.com
Wow, when I think of the hassle I went through writing JS to do this on my site a few years ago, and now HTML5 makes it that easy now! I shouldn't be bitter, but I am :)

Jens

unread,
Dec 6, 2012, 8:14:16 AM12/6/12
to google-we...@googlegroups.com
Well if you want it in IE < 10 you still need JS to do so. Simply read the placeholder attribute through JS and set the value into the Textbox if the textbox is empty and not focused. On focus clear the textbox if it contains the placeholder text.

-- J.
Reply all
Reply to author
Forward
0 new messages