Skip Navigation

[Resolved] "–Choose from the list–" dropdown options for taxonomy in post form

This support ticket is created 4 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by petarG-2 4 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#1576377

Hi,

How to have a empty / not pre-loaded by default field with the first option when creating a post from with taxonomies. The needed output is to have front-end form that with have all options at drop down menus starting with "--Choose from the list--".

BR,

P

#1576679

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Petar

Unfortunately, this currently isn't an available option, though we do have quite a few requests for it and internally this has been added to a development board to be worked on "soon", though I can't be any more specific that that.

In the meantime, you need to add a little JS to the form to insert empty options into the taxonomy selectors.

Examining the markup on the front end, taxonomy select dropdowns have name attributes such as "status[]" or "priority[]", i.e. they always end with square brackets, so we can use that to automatically select any number of taxonomy selectors in the form and add an initial empty option like so:

(function ($) {
    $(document).ready(function () {
        $("select[name$='[]']").prepend('<option value="">--Choose from list--</option>');
        
        $("select[name$='[]']").each( 
            function( index ){ 
                $(this)[0].selectedIndex = 0;
            } 
        );
    });
})(jQuery);

Add that to the custom JS section of your form.

Let me know if you have any problems.

#1582249

My issue is resolved now. Thank you!