View Full Version : TextField: how to implement setVisibleLength
7 Jan 2010, 12:14 PM
I am converting some code from GWT to GXT.
In GWT we used PasswordTextBox.setVisibleLength(vlen) to control the displayed length of the text box.
Now, in GXT, I want to use TextField, but I can't seem to figure out how to get the same setVisibleLength() functionality to work.
1. DOM.setElementPropertyInt(textField.getElement(), "size", vlen);
This appears to have no effect - wondering if the div wrapping this input element is getting in the way of that working?
2. textField.setWidth(vlen + "em") - also tried "en" and "ex"
This has some effect in that it shortens the field slightly, but not anywhere near the expected len.
Any help much appreciated,
DOM.setElementPropertyInt(textField.el().firstChild().dom, "size", vlen);
make sure to run that after rendering.
7 Jan 2010, 12:54 PM
Hmm - so I tried that and although I can see that the size attribute is indeed getting set on the input element (see below), it is not affecting the displayed size. If I remove the style="width: 150px;" in the input element using firebug, then it seems to work as expected.
Is there a reasonable way in code to avoid getting that style set? I'm not sure where that is coming from?
The html ends up looking like:
<div id="x-auto-0" class=" x-form-field-wrap " style="width: 150px;">
<input id="x-auto-0-input" class=" x-form-field x-form-text" type="password" name="password" tabindex="0" style="width: 150px;" size="8"/>
It gets set by the formlayout (i guess). As you never posted any testcase, nobody can answer this question.
20 Jul 2010, 1:54 PM
So - I have another project where I have this same issue/requirement to set the visible length of a field.
I have an example set of code that I'll attach where you can see this issue (Sven - this should look familiar since it's almost the same formfield example you were just answering validation questions on for me...).
Anyway - take a look at the first tab. There is an Age field that I'd like to set the visible length (aka the html size attribute) to 3.
I used your response from above to use
DOM.setElementPropertyInt(age.el().firstChild().dom, "size", vlen);
post-render, but it does not work.
You need to remove the width that was set on the input element
20 Jul 2010, 3:22 PM
Got it - took me awhile to figure out the right incantation to remove the width:
age.el().firstChild().setStyleAttribute("width", ""); // post-render
I swear I tried that initially, but must have been unsetting width incorrectly.
Thanks again for the help.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.