Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a project where our design has input fields with specialized default placeholder text--'Select your grade', 'Select subject(s)', etc. It would be great if these fields could be set up to have placeholder text that differs from the configured settings.
Comments
Comment #1
Dave ReidI was going to recommend that we support existing solutions like https://drupal.org/project/field_placeholder but then I came across https://github.com/harvesthq/chosen/pull/1342 which means we'd need to add support specifically for data-placeholder ourselves in field widgets.
Comment #2
lslinnet CreditAttribution: lslinnet commentedJust to repeat what they said in the linked issue and give an example for use here:
Add an attribute called data-placeholder to the select box with the placeholder text.
Example:
Perhaps adding a link to the related chosen document or give an example of how to do it within the readme?
Link to chosen documentation: http://harvesthq.github.io/chosen/#default-text-support
Comment #3
capfive CreditAttribution: capfive commentedwent looking for this feature this morning, it's a must have becuase usually the chosen interface is used in an anonymous/authenticated user setting to give better UX.
I found this https://www.drupal.org/project/field_placeholder and i wonder if someone would be able to have it apply to the chosen setup?
At the moment it just targets CCK text fields, Long text & Long text with summary, or could someone utilize the code to put it into the chosen setup?
This is a phenomenal module and really polishes off sites when it is used properly, would be great to have this feature, as at the moment I am overriding each field to put a placeholder in, and when you have more than 3 fields per content type, it's A LOT of overrides to get it to look perfect.
+1 for this feature :)
Comment #4
FluxSauce CreditAttribution: FluxSauce at Four Kitchens commentedLooks like I wasn't the only one with this need. I'd say this is documentation, as this works:
Comment #5
jonathanshawIdeally this would be exposed in the widget settings UI, as some other widgets do.
Comment #6
cdmo CreditAttribution: cdmo commentedJust another example of #2, this time applied in a hook_form_alter (in my case to an exposed view filter):
Comment #7
serundeputy CreditAttribution: serundeputy at Tandem for Backdrop CMS commentedNot sure if the examples in #6 and #4 are for D7 or D8, but in D8 they are having no effect on the placeholder text for me.
In my case the field is an Unlimited number of values select list.
Comment #8
cdmo CreditAttribution: cdmo commented#6 is for D7
Comment #9
chucksimply CreditAttribution: chucksimply commentedFinally worked out a D8 solution. Hope this helps some.
Comment #10
texas-bronius CreditAttribution: texas-bronius at Ocelot commentedThanks ChuckSimply. I'll just mention this is true of custom select elements (ie. no hook_form_alter required) like:
Terrific! One step cooler would be for Chosen module to adjust field widget settings and expose a per-field placeholder text field just like autocomplete entity reference has.