How to set formItem Label programmatically

Hi all !

We use <formLayout labelsPosition="ASIDE">.

It is possible to set the label of a <textField>. This label is fixed on the top of the textfield.

the labelsPosition="ASIDE" does change the label position of the <formItem> !

How to set the label of the from the controller ?

Best regards

Felix

Hi all !

Found a solution which is quit generic. I think, there should be an easier solution; but I have to deliver ;/

@ViewComponent
private FormLayout form;

protected void onInit(InitEvent event) {
  // all components of this form
  List<Component> f = form.getChildren().toList();
  for (Component component : f) {
    // search in all components for the label
    List<Component> l = component.getChildren().toList();
    for (int c = 0; c < l.size(); c++) {
       if (component.getElement().getChild(c).getAttribute("slot") != null &&
             component.getElement().getChild(c).getAttribute("slot").equals("label")) {
         component.getElement().getChild(c).setText("labelText");
      }
  }
}

There is more logic, as not all field labels will have the content labelText, but this is a solution how i could set the label on the <formItem>

Hopefully it is usefull for somebody.

Felix