Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Dynamically add FormItem to Form

    is it possible to dynamically add FormItem to a Form? That is, if i click on a button to add some FormItems to an existing DynamicForm?

    i have tried to test, but it does not work. because setFields() or setItems() does not work like addMember().

    Code:
     
    public class smd implements EntryPoint {
    
        public void onModuleLoad() {
          
          VLayout layout = new VLayout();      
          Button button = new Button("Add");            
          final DynamicForm form = new DynamicForm();
          
          button.addClickHandler(new ClickHandler(){
    
            public void onClick(ClickEvent event) {
              for(int i = 0; i<5; i++){
              TextItem item = new TextItem();
              form.setFields(item); 
              }
            }        
          });
          
          layout.addMember(button);
          layout.addMember(form);     
          layout.draw();
      }
    }
    Does anyone have an idea about how to handle this?
    thanks a lot.

    #2
    setFields() replaces all existing fields. Two options:

    1. if all the fields are known in advance, mark some initially hidden and show them later.

    2. if it's completely dynamic, use multiple forms and tie them together with a ValuesManager, visually stacking them with a VStack.

    Comment

    Working...
    X