Agregue dinámicamente un FormItem a un DynamicForm con 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.

preguntado el 08 de noviembre de 11 a las 18:11

1 Respuestas

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.

Respondido 07 Feb 13, 22:02

Thank you for your answer. I edited my question in order to be more clear. - Alexis Dufrenoy

So there is no way to change dynamically a DynamicForm. I can't see a good reason why it's done that way, from a Javascript point of view. It's a bit disappointing... - Alexis Dufrenoy

? There are three ways to do so as described above, and your use case seems to be well handled by #2. If an addField API were available, it doesn't seem like it would meaningfully shorten or simplify the code. Also, an addField() API has the potential for some surprising consequences if you think through how it should interact with DataSource binding and the form's existing values, that's part of why we haven't added such as an API, and recommend the three approaches above. - Charles Kendrick

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.