Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LiveComponent] onUpdated don't triggered when using ComponentWithFormTrait with LiveProp to edit #2258

Open
akyoscommunication opened this issue Oct 11, 2024 · 2 comments

Comments

@akyoscommunication
Copy link

          Hello, I also have the same problem,

I also have the same problem. After some research, I noticed that when using a LiveProp assigned to a form that is instantiated with ComponentWithFormTrait, the variable name must not be the same as the form name.

example:

    #[LiveProp(writable: true, updateFromParent: true, onUpdated: 'onUpdatedComponent')]
    public Component $component ;

    protected function instantiateForm() : FormInterface
    {
        return $this->createForm(ComponentType::class, $this->component) ;
    }

error :

An exception was thrown when rendering a model ("The field name ‘component’ cannot be used by multiple LiveProp properties in a component. Currently, “component” and “formValues” are both trying to use it in “xxx”. Try adding LiveProp(fieldName=“somethingElse”) for the “component” property to avoid this.").

Consequence:

If we change our variable like this

    #[LiveProp(writable : true, updateFromParent : true, onUpdated : 'onUpdatedComponent')]]
    public Component $c ;

    protected function instantiateForm() : FormInterface
    {
        return $this->createForm(ComponentType::class, $this->c) ;
    }

The onUpdated function cannot be triggered because, on line 664 of ux-live-component/src/LiveComponentHydrator.php, the $frontendName variable is equal to “c”. However, what we want is to have “component”, since on line 673, we check whether we have “c” in $dehydratedUpdatedProps. But the problem is that in this last variable, the Live Component only updates the “component” variable, since it's the form variable and not the variable name passed to LiveProps.

I hope I've made myself clear :D
Thanks in advance

Originally posted by @akyoscommunication in #2057 (comment)

@smnandre
Copy link
Member

Did you try doing what the error suggest ?

   #[LiveProp(fieldName="foo", ....)]
    public Component $component

@akyoscommunication
Copy link
Author

There is no errors. Just, the onUpdate function don't trigger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants