Announcement

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

    Best practice: DynamicForm with changing FormItem-list

    Hi Isomorphic,

    what's the correct/suggested way implementing of a DynamicForm with different FormItems (after some user action some FormItems will be shown and some will be hidden).

    How would one add/remove fields from a DynamicForm? It has no removeFields-method and calling setFields again with a slightly different field-list but with the same objects for the fields present before and after results in a warning (ID collision). So I have to add all fields in advance and work with myFormItem.show() / myFormItem.hide(), correct?

    Thank you & Best regards
    Blama

    #2
    There's no single best practice here, it depends on what the use case is.

    If you have a few fields that are conditionally editable or conditionally shown, generally you define all the fields up front then show and hide them.

    If the set of fields is more dynamic than that, then it's unclear why you would think of them as fields for the same form. Just use a new form, or completely replace all fields via setFields().

    As far as correct use of setFields():

    1. you are not allowed to re-use the same FormItem instances. So this just means you should create a method that can return the FormItems you need, and call it more than once

    2. if you are assigning IDs to FormItems, one way to get rid of the old items before creating their replacements is to call setFields() with a blank array before calling setFields() with new items. But again here, it's not clear what the purpose of reusing the same DynamicForm instance would be, if all the items are being replaced.

    Comment


      #3
      Hi Isomorphic,

      Originally posted by Isomorphic View Post
      If you have a few fields that are conditionally editable or conditionally shown, generally you define all the fields up front then show and hide them.
      That is exactly my use case - hide one CheckboxItem, show one ButtonItem.

      Originally posted by Isomorphic View Post
      1. you are not allowed to re-use the same FormItem instances. So this just means you should create a method that can return the FormItems you need, and call it more than once

      2. if you are assigning IDs to FormItems, one way to get rid of the old items before creating their replacements is to call setFields() with a blank array before calling setFields() with new items. But again here, it's not clear what the purpose of reusing the same DynamicForm instance would be, if all the items are being replaced.
      That is great to know as well. Perhaps this is valueable information for DynamicForm.setFields(). Also "Form Layout" there does not link to the FormLayout-docs.

      Thank you for the insight & Best regards
      Blama

      Comment

      Working...
      X