• Resolved johny66cz

    (@johny66cz)


    Hello, I would like to return the option to have an empty field in Dropdown like in previous versions. Now there is always text even when it is empty. Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Ralden Souza

    (@rsouzaam)

    Hi @johny66cz,

    Thanks for reaching out!

    This can be accomplished with a little custom code:

    function wpf_dev_empty_dropdown_item() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function($) {
            // Find the option with the default text format "Choice {ID}" and change it to empty ""
            $('.wpforms-field-select select option').each(function() {
                var defaultOptionRegex = /^Choice \d+$/; // Regular expression to match "Choice {ID}"
                if (defaultOptionRegex.test($(this).text())) {
                    $(this).text('');
                }
            });
        });
    </script>
    <?php
    }
    add_action('wpforms_wp_footer_end', 'wpf_dev_empty_dropdown_item', 30);

    Please kindly know this code requires using the Classic Dropdown style.

    In case it helps, here’s our tutorial with the most common ways to add custom code like this.

    For the most beginner-friendly option in that tutorial, I’d recommend using the WPCode plugin.

    I hope this helps!

    Thread Starter johny66cz

    (@johny66cz)

    Hi, thanks for the quick reply. It does not work for me.

    (But it did something. I deleted this php, restored older WPForms backup and now I see Choice 0 as admin everywhere. As a visitor, it is empty how it was.)

    • This reply was modified 9 months, 2 weeks ago by johny66cz.
    Plugin Support Ralden Souza

    (@rsouzaam)

    Hi @johny66cz,

    Thanks for letting us know!

    I’d like to share that I added the code snippet above on my test site (screenshot), and created a Dropdown field with an empty option (screenshot). Then, the empty option was available in the form (screenshot).

    But I’m glad to hear you got that sorted, and thank you for taking the time to let us know.

    If you’d like more help with using WPForms Lite, please feel free to reach out.

    Thanks!

    Thread Starter johny66cz

    (@johny66cz)

    Hi, it’s working now. I just had to replace the word “Choice” with the czech word “Volba” because I have a translation. Thanks a lot.

    Thread Starter johny66cz

    (@johny66cz)

    I take it back. It works on the web and you can see the empty field. However, after submitting the form, the Choice text + number appears in the email. Correctly, the Dropdown shouldn’t submit at all.. I have to backup older version of WPForms unfortunately.

    Plugin Support Ralden Souza

    (@rsouzaam)

    Hi @johny66cz,

    Thanks for letting me know!

    The Dropdown field is showing that “Choice + number” in notifications to let you know which option was selected in the Dropdown field.

    In case you don’t want to receive the Dropdown field in notifications in case users do not select an option, the best solution would be to remove that empty option and add a text to the Placeholder Text option (screenshot).

    Hope this helps!

    Plugin Support Shawon Chowdhury

    (@shawon001)

    Hi @johny66cz,

    We haven’t heard back from you in a few days, so I’m going to go ahead and close this thread for now. But if you’d like us to assist further, please feel welcome to continue the conversation.

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘No empty field in Dropdown’ is closed to new replies.