Closed waterhd closed 1 year ago
@waterhd first of all, thank you for using my components!
in general, collection field does not add elements to the collection - it only adds a new component using CollectionValueComponentProvider
; so one way to add an existing object is to just have an implementation of that interface that does it (i.e. it creates a component and sets its value to whatever object you want)
the other option is to get the value of the collection field, then create a new collection with elements from that and the new element, then set the value of the collection field to that :) a bit convoluted, though (simply getValue().add(object)
will not work, as the value of the field has not changed - it is still the same collection)
Dear Miki
Thank you for your suggestions. I managed to get it working this way. Providing layout is still a bit challenging even when looking at the demo but I’m sure it’s just a bit of a learning curve.
Regards Dennis
On Mon, 19 Dec 2022 at 11:46, Miki @.***> wrote:
@waterhd https://github.com/waterhd first of all, thank you for using my components!
in general, collection field does not add elements to the collection - it only adds a new component using CollectionValueComponentProvider; so one way to add an existing object is to just have an implementation of that interface that does it (i.e. it creates a component and sets its value to whatever object you want)
the other option is to get the value of the collection field, then create a new collection with elements from that and the new element, then set the value of the collection field to that :) a bit convoluted, though (simply getValue().add(object) will not work, as the value of the field has not changed - it is still the same collection)
— Reply to this email directly, view it on GitHub https://github.com/vaadin-miki/super-fields/issues/447#issuecomment-1357447924, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIXMIECVP5IJVWACRGE3KXLWOA4H3ANCNFSM6AAAAAASZEKQJA . You are receiving this because you were mentioned.Message ID: @.***>
--
M.vr.gr.
Dennis
CollectionField allows adding a new row using .add() or .add(index), but this element is null by default. How to best add a new or existing object?