Aleš Sýkora wrote

Set Dropdown Field Default Value from — Not set — in Toolset With Javascript

30. 8. 2019 in

If you want to change the -not set- text when using the dropdown field in Toolset form, you must use custom JavaScript. Here is a tutorial how to do it.

Before

Dropdown field default value -- not set -- in Toolset Form
Dropdown field default value — not set — in Toolset Forms

After

Dropdown field default value set with jQuery in Toolset Forms
Dropdown field default value set with jQuery in Toolset Forms

Option 1: Custom Javascript rule to set default dropdown value

Your dropdown field should look like this:

[cred_field field='field-name' force_type='field' class='form-control' output='bootstrap' value='']

Open the form editor and click to the JS editor. Add the jQuery code from below and do not forget to change the field-name and Your-text values ;-).

jQuery(document).ready(function($){
   
 $("select[name='field-name'] option[value='']").text("Your-text");
 
});
Custom Javascript metabox in Toolset Form
Custom Javascript metabox in Toolset Form

Option 2: Custom filter

If you want to change the text globally for all dropdowns, use this filter in your custom code snippets plugin.

function changenotset($current_options, $title, $type) {
     foreach ($current_options as &$option) {
         if ($option['#title']=='--- not set ---') {
             $option['#title'] = "my new default value";
         }
     }
     return $current_options;
 }
 add_filter("wpt_field_options", 'changenotset', 10, 3);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Make slow YouTube embed faster with Toolset
12. 11. 2018 in
Speed up your Toolset website with YouTube embeded videos. Load them faster in a minute. Try it right with this tutorial.
Read More
Aleš Sýkora wrote
Custom SCROLLBAR with Oxygen Builder
7. 12. 2020 in ,
Are you looking for some cool scroollbar, like on CSS-Tricks website? for a specific DIV use this in your custom CSS: for a whole document use body instead.
Read More
Aleš Sýkora wrote
Oxygen Repeater Pagination not working on homepage
When you use repeater on static front-page of your WordPress site and you also wants to use pagination – it doesn’t work at all. It stops at /page/2 and never display /page/3. It still repeat the second page. However – it looks like Oxygen bug, but it is not. As you can see: https://codex.wordpress.org/Pagination#static_front_page. To […]
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram