ux
ux copied to clipboard
[LiveComponent] data-model="on(change)|*" is not re-added
I've updated live component to v2.3 but it broke my dynamic forms:
- On initial rendering I see that
data-model="on(change)|*"is added on the form element; - I update some input or select a checkbox, data is sent to backend;
- Re-rendered
Hey @norkunas!
Hmm. So this is added by the useNameAttributesAsModelName() method being called - https://github.com/symfony/ux/blob/8e84d49a92b70f99001b8817cd3129a6215175f6/src/LiveComponent/src/ComponentWithFormTrait.php#L195-L206.
That method should automatically be called either by initializeForm() in the trait (which is done on PostMount, so it, indeed, would NOT be called in re-render) OR from getForm() in the trait - https://github.com/symfony/ux/blob/8e84d49a92b70f99001b8817cd3129a6215175f6/src/LiveComponent/src/ComponentWithFormTrait.php#L122
So, it seems that somehow getForm() is never being called on your trait? But I don't see how that's possible on re-render. Can you confirm whether or not getForm() is being called on re-render?
Hey, then it's probably because my form is a multistage and there is prev/next stage buttons, so they recreate totally different form based on the stage. Sadly useNameAttributesAsModelName is private, so will need to duplicate it then :)
If we need to add flexibility for useNameAttributesAsModelName, then let's do it.
Sorry, looked again to this and found that useNameAttributesAsModelName is private but it's in a trait, so I can use it :)