ux icon indicating copy to clipboard operation
ux copied to clipboard

[LiveComponent] data-model="on(change)|*" is not re-added

Open norkunas opened this issue 3 years ago • 3 comments

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
    does not have data-model="on(change)|*" and any subsequent form changes fails.

norkunas avatar Jul 18 '22 07:07 norkunas

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?

weaverryan avatar Aug 03 '22 14:08 weaverryan

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 :)

norkunas avatar Aug 03 '22 14:08 norkunas

If we need to add flexibility for useNameAttributesAsModelName, then let's do it.

weaverryan avatar Aug 11 '22 20:08 weaverryan

Sorry, looked again to this and found that useNameAttributesAsModelName is private but it's in a trait, so I can use it :)

norkunas avatar Sep 15 '22 06:09 norkunas