-
-
Notifications
You must be signed in to change notification settings - Fork 380
Description
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)