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

[LiveForm] $this->formValues doesn't work #2577

Open
GrinWay opened this issue Feb 17, 2025 · 3 comments
Open

[LiveForm] $this->formValues doesn't work #2577

GrinWay opened this issue Feb 17, 2025 · 3 comments
Labels
LiveComponent question Further information is requested

Comments

@GrinWay
Copy link
Contributor

GrinWay commented Feb 17, 2025

Bug:

When I change payload from frontend with $this->formValues I expect the form to be rerendered with changed data, BUT form renders as though I didn't change the payload wiht this->formValues

Description:

I have a live form, then type something (for triggering an AJAX), method instantiateForm is called and in this method I change user's payload with $this->formValues live prop, then I expect to see changes accrdingly my changes in $this->formValues live prop, BUT I see data that haven't been changed.

Reproduce:

CustomFormType

public function buildForm(FormBuilderInterface $builder, array $options): void
{
    $builder->add('plannedAt', DateTimeType::class, ['widget' => 'choice']);
}

LiveFormClass

#[AsLiveComponent]
class LiveFormClass extends AbstractController {
    #[LiveProp]
    public ?Order $initialFormData = null;

    protected function instantiateForm(): FormInterface
    {
        $this->setMinimumAvailablePlannedAtToTheFrontendPayload();
        return $this->createForm(CustomFormType::class, $this->initialFormData);
    }

    private function setMinimumAvailablePlannedAtToTheFrontendPayload(): void
    {
          // CHANGE PAYLOAD DATA TO MAKE THE FORM TO BE RERENDERED DIFFERENTLY, BUT IT DOESN'T WORK
          $this->formValues['plannedAt']['date']['year'] = '2000';
    }
}

Maybe it's because of DateTimeType?!

@GrinWay GrinWay added the Bug Bug Fix label Feb 17, 2025
@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label Feb 17, 2025
@GrinWay
Copy link
Contributor Author

GrinWay commented Feb 17, 2025

I was on symfony 7.2 and live components 2.3
But later used symfony 6.4.18 and live component 2.8
Useless, nothing helped, still breaking my head how to refresh the form view BUT I have a valid model data (2000 year in the entity)
But not in the form view🥸

@GrinWay
Copy link
Contributor Author

GrinWay commented Feb 19, 2025

I noticed that form field (using ComponentWithFormTrait) doesn't change itself when it's selected... strange

@smnandre
Copy link
Member

I'm sorry, but I'm not sure I fully understand what you were trying to do. However, I'm fairly certain this isn't a documented feature :)

So the 'bug' classification might be a bit... overstated.

Now, here is some part that may interest you: https://symfony.com/bundles/ux-live-component/current/index.html#dynamically-updating-the-form-in-a-liveaction

@smnandre smnandre added question Further information is requested LiveComponent and removed Bug Bug Fix Status: Needs Review Needs to be reviewed labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LiveComponent question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants