-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Twig, Form Types] Form text field placeholder can not be null. Why? #37573
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
Comments
Can you explain why you would want to set the |
Because placeholder comes from database and sometimes can be null value. |
@xabbuh I had the same issue some time ago. If you have an optional placeholder, this one is way easier: $form
// 10 Form Fields
->add("someField", null, [
// ...
"attr" => [
"placeholder" => $data->getPlaceholder(),
],
])
// 4 more form fields instead of $someFieldAttributes = [
// ...
];
if (null !== $data->getPlaceholder())
{
$someFieldAttributes["attr"]["placeholder"] = $data->getPlaceholder();
}
$form
// 10 Form Fields
->add("someField", null, $someFieldAttributes)
// 4 more form fields
|
Please have a look at #38595. Does it work for you? |
…(xabbuh) This PR was merged into the 3.4 branch. Discussion ---------- [TwigBridge] do not translate null placeholders or titles | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #37573 | License | MIT | Doc PR | Commits ------- 2ee24a0 do not translate null placeholders or titles
Looks great, thanks @xabbuh ! 🎉 |
Symfony version(s) affected: 5.1.2
Description
Form input placeholder can be empty string or false but can not be null. Why?
Another attributes like for example class can by null.
Error: Argument 1 passed to Symfony\Bridge\Twig\Extension\TranslationExtension::trans() must be of the type string, null given
How to reproduce
The text was updated successfully, but these errors were encountered: