Open pschiffe opened 3 months ago
You've given the css classes, but those are a lot less useful than what the actual underlying PHP FormField
implementation is.
If it's being autoscaffolded, that will be a DropdownField
. I've played around a bit with the code that scaffolds the form field. It turns out that ' '
is a bit magic. If that was an empty string, or a string containing some text, the empty string or text would be displayed. But for some reason chosen
looks at the ' '
differently.
"Select an Option" is the default placeholder text for chosen dropdowns.
There are a couple of ways to tackle this:
DBForeignKey
autoscaffolding
This would be adding something like ->setAttribute('data-placeholder', _t(__CLASS__ . '.SelectOption', 'Select an Option'))
to the fieldDropdownField
which has this setup
This would be more complicated, since it seems like it's being done as a fluke (that someone noticed and intentionally used in the autoscaffolding scenario).
This requires finding out what the exact conditions are which cause the default text to be used (e.g. is it a single space specifically? Or any amount of whitespace? etc) and setting a data-placeholder
only in those scenarios.As an aside, the autoscaffolded FormField
for has_one
relations is changing in Silverstripe CMS 5.2.
Hi @GuySartorelli, great job looking into this, thank you. Yes, it's autoscaffolded, I didn't know quickly what else to show you except the CSS :sweat_smile:
Looking at the code you linked, I don't think there's an easy workaround, right?
Reg. the proposed solutions, I don't know what would be the best, nb. 1 seems reasonable to me.
Option 1 is definitely the least intrusive - but it could result in unexpected behaviour in the (unlikely) scenario someone creates their own DropdownField
with whitespace as the "empty string".
Given the extra complexity of option 2 though, I'd be okay with a PR that just implements the first option.
Module version(s) affected
2.1.17
Description
The
$has_one
relation ofDataObject
renders in the admin as a dropdown. And if this relation doesn't have some default configured, it shows textSelect an Option
, for example, when creating a new instance of theDataObject
class.The text probably comes from some 3rd party, it doesn't seem to react to the browser language settings. The classes around the dropdown are:
chosen-container chosen-container-single chosen-container-single-nosearch
andchosen-single chosen-default
.Could you help me to identify the said 3rd party library and maybe find a way how to translate it? In the Silverstripe v3 there was no text visible.
How to reproduce
Possible Solution
No response
Additional Context
No response
Validations
silverstripe/installer
(with any code examples you've provided)