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

Set non displayed property to null #3

Open
mpiot opened this issue Sep 8, 2023 · 2 comments
Open

Set non displayed property to null #3

mpiot opened this issue Sep 8, 2023 · 2 comments

Comments

@mpiot
Copy link

mpiot commented Sep 8, 2023

When the dependent field is not displayed, but is previously set, it should be nice to set it to null or a default value we want.
I don't really know if this can be implemented rirectly, or maybe, mentioned in the documentation to remind people implement it.

Eg:

public function setMeal(Meal $meal): static {
    $this->meal = $meal;

    if ('breakfast' !== $meal) {
        $this->rating = null;
    }

   return $this;
}
@weaverryan
Copy link
Contributor

Yes... I haven't really thought about this. I guess, inside the form, if 'breakfast' !== $meal, the rating field will be removed... so the result would be that setRating() is never called... and so it would keep whatever value it had when the object was first passed to ->createForm() (i.e. the value set in the database).

Can you confirm that my statement above is accurate? If so, yes, my feeling is that this would be a good fit for the docs.

@mpiot
Copy link
Author

mpiot commented Sep 22, 2023

Yes, because we remove a field, then we never call the setter and the object keep the initial value.

I don't really know which is the best way to change that value:

  • setter
  • change the data when removing or not adding the field
  • add a final POST_SUBMIT event that check for example: if 'breakfast' !=== getMeal() then setRating(null)

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

No branches or pull requests

2 participants