View Full Version : Bug with setName for Field?

5 Jun 2008, 12:16 PM
If I call Field.setName() on a form field before it's rendered, then the name gets lost on rendering. This is because getName() will return the underlying element's name field if it's rendered, and not the Field.name, and the element name is not getting set properly.

in Field.onRender() you can see:

if (getName() != null) {
getInputEl().setElementAttribute("name", getName());

and getName is this:

public String getName() {
return rendered ? getInputEl().getElementAttribute("name") : name;

well, at this point in onRender the "rendered" variable is true, so getName returns the blank name attribute on the element, not the Field.name, so nothing gets set on the element, and since getName() won't let you get at the Field.name after rendered is true, the name is pretty much lost. I haven't tried it, but this should fix it:

if (name != null) {
getInputEl().setElementAttribute("name", name);