Search code examples
smartgwt

Add dynamically an FormItem to a DynamicForm with SmartGWT


I would like to add a FormItem to a DynamicForm in a SmartGWT form, but all I can find is the setItems method, which adds all FormItem of the form, so it can only be used to initialize the form. Am I missing something?

My form contains a TextItem, and each time the user enters a new string and validate, a new CheckButton is added.


Solution

  • Best approach depends on what you want to do:

    1. Dynamically shown item? Add it to the form at initialization, but hidden, then show() it later

    2. repeating form, like the built-in FilterBuilder component? Just add a series of DynamicForms to a Layout, consider tying them together with a ValuesManager

    3. something else? Consider either #2 above, or, setItems() can be used as a means of providing just one new item to the form, just provide a new Array of FormItems including the items you already have. The form will automatically preserve the item's current values.