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

Field's setDefault not called if value is an array (like in Map field) #5828

Open
alexoleynik0 opened this issue Sep 29, 2023 · 0 comments
Open

Comments

@alexoleynik0
Copy link

  • Laravel Version: 9.50.2
  • PHP Version: 8.0.2
  • Laravel-admin: 1.8.19

Description:

There's an issue with Encore\Admin\Form\Field->value method.

Because it checks only for $this->value to not be equal to null (using null coalescing operator -- return $this->value ?? $this->getDefault();).
Hence it does not get to the getDefault method if $this->value is something else from null.

For example Encore\Admin\Form\Field\Map field has value set to an array with empty values:

protected $value = [
    'lat' => null,
    'lng' => null,
];

Not sure whether it should be fixed explicitly for Map field or for Field alltogether.

Described it some more in this comment -- there're some workarounds also.

Steps To Reproduce:

  1. Create Form with Map field -- $form->map('lat', 'lng', __('Location'));.
  2. Set default value using default method
$form->map('lat', 'lng', __('Location'))->default(['lat' => 50.454476779599574, 'lng' => 30.517363595654306]);
  1. See that it doesn't work for Creation nor for Editing of the Entity.
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

1 participant