-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
[UX] Live component - form select required not initialized #1332
Comments
Hey, thanks for your report! |
Hello? This issue is about to be closed if nobody replies. |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
Hello, I have exactly the same problem ! |
Same problem, cannot submit live form with default values for select and entity types |
How would you handle this ? |
@smnandre the solution proposed by @BriceFab seems to be a goode idea, The values should be extracted and defined in ComponentWithFormTrait::extractFormValues. Actually to make my form works, I had to do a dirty workaround in the form: public function finishView(FormView $view, FormInterface $form, array $options): void
{
$this->initChoiceValue($view, 'notation');
}
private function initChoiceValue(FormView $view, string $key): void
{
if ($view[$key]->vars['value'] === "" && array_key_exists('choices', $view[$key]->vars) && count($view[$key]->vars['choices']) > 0) {
$view[$key]->vars['value'] = key($view[$key]->vars['choices']);
}
} |
Would one of you people be ready to open a PR ? (We can iterate on "details" things, but this could be a good base :)) |
I can do it but not right away, I'm overwhelmed in the short term and I already have another PR to create and submit to you following another bug found. If someone else can do it that's great, otherwise I'll take care of it as soon as possible |
Something like this ? // ...
if ($child->vars['required'] && $values[$name] === null) {
// Select the first element if available (can be an empty placeholder)
if (0 < count($choices = $child->vars['choices'] ?? [])) {
$values[$name] = reset($choices);
continue;
}
throw new UnprocessableEntityHttpException(sprintf('The required field "%s" is missing and has no default value.', $name));
}
|
Symfony version(s) affected
6.3.10
Description
Class: Symfony\UX\LiveComponent\ComponentWithFormTrait::extractFormValues
Doesn't extract required values for select / entity type field:
The default value should be '1'.
This is the FormType:
How to reproduce
Create a form type with ux live component and required entity type field.
https://symfony.com/bundles/ux-live-component/current/index.html#forms
Possible Solution
If select / entity type and required, extract the default value
Additional Context
No response
The text was updated successfully, but these errors were encountered: