PDA

View Full Version : Set field labels after rendering a form panel



zaccret
9 Jun 2008, 11:27 PM
If a form panel is already rendered, you cannot change the field labels with Field.setFieldLabel(String). This is blocking me, since I'm using RPC for internationalization. It would be nice to make it possible. Any workaround ?

zaccret
17 Jun 2008, 5:33 AM
Nobody have the need to change a field label ? :(

darrellmeyer
17 Jun 2008, 7:26 AM
Changing the labels after the form is rendered is not really feasible. Can you make your RPC call first, set the fields labels, then render the form?

zaccret
17 Jun 2008, 10:13 PM
Well, if it is really not feasible, I will try what you say : set the fields label before rendering. However, it is restrictive as I will have to add the form panel to its container (render the form) IN the internationalization callback (to ensure that the form is rendered AFTER the field labels are set). I will also have to change my design, because I often indirectly set the labels in the initialize() method and I add the form panel on the handleEvent() method.
However, I would greatly appreciate a workaround, if possible :">

zaccret
19 Jun 2008, 4:39 AM
If you don't want/cannot refactor, I believe there must be a way to retrieve the HTML node associated with the label. I tried the following code, but it does not work :

Element el = field.getElement();
Node labelElement = el.getPreviousSibling();
labelElement.setNodeValue(myI18NLabel);

gslender
19 Jun 2008, 4:51 AM
you might have to rethink the relationship as I don't think its previous sibling.... looks like its the parents-previous-sibling ???

Code is from a form field password and label.


<div class="x-form-item" tabindex="-1">
<label class="x-form-item-label" style="width: 100px;" for="my-44">Password:</label>
<div id="x-form-el-my-44" class="x-form-element" style="padding-left: 105px;">
<input id="my-44" class="x-form-field x-form-password x-form-text" type="password" tabindex="0" style="width: 200px;"/>
</div>
<div class="x-form-clear-left"/>
</div>

darrellmeyer
19 Jun 2008, 5:09 AM
gslender is correct. Also, the relationship will vary by field. Here is some example code that should work. However, the label separator is hardcoded:



text.el().findParentNode(".x-form-item", 5).firstChild().setInnerHtml("Changed:");

zaccret
20 Jun 2008, 1:01 AM
:) Thanks a lot, guys, it works well

sdc
20 Jun 2008, 3:10 AM
Anyway, it would be useful to be able to change the field labels after form rendering, as you can do for a lot of other widgets (MenuItem, ContentPanel, TabItem, Button...), without having to manage with DOM elements.

sdc
20 Jun 2008, 3:29 AM
At least, maybe we could have something similar to the DataListItem.setText(String) method :

public void setFieldLabel(String fieldLabel) {
this.fieldLabel = fieldLabel;
if (rendered) {
El elem = el().findParentNode(".x-form-item", 5).firstChild();
elem.setInnerHTML(fieldLabel+fieldSeparator);
}
}

darrellmeyer
22 Jun 2008, 6:30 PM
Change is in SVN.

sdc
25 Jun 2008, 7:19 AM
Nice job. Thanks, Darell.

doright
7 Jan 2010, 9:34 AM
At least, maybe we could have something similar to the DataListItem.setText(String) method :

public void setFieldLabel(String fieldLabel) {
this.fieldLabel = fieldLabel;
if (rendered) {
El elem = el().findParentNode(".x-form-item", 5).firstChild();
elem.setInnerHTML(fieldLabel+fieldSeparator);
}
}

Hi folks,
I'm new-ish to using GWT and ext GWT and have been trying to use setFieldLabel(). So I read this forum entry with interest. I see that the last post was over a year old, so I wonder 2 things, any updates on it? if not, please explain in a little more detail how I implement the work-around. Many thanks.