Announcement

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

    How can I dynamic add form item during one of the item value changed.

    Such as I have a drop down pick list to select one type, then generate different number of new Item to the form.
    For current I can only do it through addItem(); but can not remove item...
    Last edited by adoin; 22 Aug 2019, 23:55.

    #2
    We're not sure of your requirements, but having the DynamicForm add or remove (many) items derived from interaction is probably not ideal. To change the item list, you'd need to call DynamicForm.setItems(), but that requires replacing all the items so you'd need to keep and pass in the complete item list each time.

    If all the items that you might need to show are known ahead of time, then you can add them all up front at the beginning with those items you don't immediately want visible marked as FormItem.visible: false. Then based on user interaction, you can show() these hidden items. You can also define FormItem.showIf to accomplish this.

    However, if the new items can only be determined based on the user interaction itself (or perhaps an unlimited number of them are possible), then the up-front approach won't work. However, in that case, adding them as FormItems is perhaps not the right approach. Instead, you may want to consider adding them as data for a SelectItem (so they'd be hidden until you popped up the list) or if your want them always visible you could add a ListGrid next to your DynamicForm and add them as records.

    You could also split out the dynamic items into a separate form so that calling setItems() doesn't disturb your core form items. Then a ValuesManager could be used to allow the forms to be saved (or values manipulated) as a single unit.

    Comment


      #3
      Originally posted by Isomorphic View Post
      We're not sure of your requirements, but having the DynamicForm add or remove (many) items derived from interaction is probably not ideal. To change the item list, you'd need to call DynamicForm.setItems(), but that requires replacing all the items so you'd need to keep and pass in the complete item list each time.

      If all the items that you might need to show are known ahead of time, then you can add them all up front at the beginning with those items you don't immediately want visible marked as FormItem.visible: false. Then based on user interaction, you can show() these hidden items. You can also define FormItem.showIf to accomplish this.

      However, if the new items can only be determined based on the user interaction itself (or perhaps an unlimited number of them are possible), then the up-front approach won't work. However, in that case, adding them as FormItems is perhaps not the right approach. Instead, you may want to consider adding them as data for a SelectItem (so they'd be hidden until you popped up the list) or if your want them always visible you could add a ListGrid next to your DynamicForm and add them as records.

      You could also split out the dynamic items into a separate form so that calling setItems() doesn't disturb your core form items. Then a ValuesManager could be used to allow the forms to be saved (or values manipulated) as a single unit.
      Thanks Finally I choose to show and hide items.

      Comment

      Working...
      X