Skip Navigation

[Resolved] Placeholder in Select Fields on Post Forms

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 5 replies, has 2 voices.

Last updated by Ed 5 years, 11 months ago.

Assisted by: Waqar.

Author
Posts
#1203174

Ed

I want to add placeholder text in two select (dropdown) fields, on a post form. So far, I've been unable to do this.

#1203576

Hi Ed,

Thank you for contacting us and I'll be happy to assist.

The placeholder text attribute can be used with a single or multiline type field, as explained at:
hidden link

If you'd like to include an empty default option in your select (dropdown) field, you can include it in the actual field's settings like shown in this example screenshot: hidden link

In case you had a different requirement in mind, please share some example and also the link to your own page with the post form.

regards,
Waqar

#1203651

Ed

Thank you, Waqar.

This is a "CRED" form, with the options pulled from existing taxonomies. There isn't a way to "add" an empty option.

#1203802

Hi Ed,

Thank you for clarifying that.

To insert an empty first select option in the taxonomy dropdown selector field, you can add the following custom script in the "JS editor" tab:
( example screenshot: hidden link )

Note: To access this option, you'll need to turn on the "Expert mode" from the top:
( screenshot: hidden link )


jQuery(document).ready(function($){
   
jQuery("select[name='tax-slug[]']").prepend('<option value="0">- Select -</option>');
jQuery("select[name='tax-slug[]']")[0].selectedIndex = 0;
   
});

Please replace both instances of "tax-slug" with your actual taxonomy's slug.

regards,
Waqar

#1203817

Ed

Thanks, Waqar! That works!

I just had to modify the code as follows (because there were two fields that needed this):

jQuery(document).ready(function($){
jQuery("select[name='resource-type[]']").prepend('<option value="0">- Select -</option>');
jQuery("select[name='resource-type[]']")[0].selectedIndex = 0;
jQuery("select[name='resource-availability[]']").prepend('<option value="0">- Select -</option>');
jQuery("select[name='resource-availability[]']")[0].selectedIndex = 0;
});

#1203819

Ed

My issue is resolved now. Thank you!