• Resolved rgreenstreet

    (@rgreenstreet)


    Hi there!

    Working with the Advanced CF7 Database plugin/add-on, is there a way to change the sort of the dropdown list of all of the CF7 forms that are feeding into the Database? The list where you click the name of the form and then it displays the spreadsheet data of the entries.

    By default it appears to be sorted by date created, which when you have 400+ forms, isn’t super helpful. I’d very much rather sort it alphabetically.

    Thank you for any insight!

    • This topic was modified 6 years, 8 months ago by rgreenstreet.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Vsourz Digital

    (@vsourz1td)

    Hello @rgreenstreet,

    Thanks, for using our plugin. We will take your concern into our consideration and keep it on our list. We will try to provide this in our upcoming versions if possible.

    We will let you know when done.

    Regards,

    Thread Starter rgreenstreet

    (@rgreenstreet)

    Thanks for the update!

    I have the same request, please. Thank you.

    I found a way based in Sorting options elements alphabetically using jQuery

    Steps:

    1. Install and activate CSS & JavaScript Toolbox WP plugin

    2. Go to plugin’s admin page at yourwebsite.com/wp-admin/admin.php?page=cjtoolbox

    3. Add a “+ New Code Block” and name it as you wish

    4. Past the following code:

    
    <script type="text/javascript">
        jQuery(document).ready(function() {
    
            function sortSelectOptions(selector, skip_first) {
                var options = (skip_first) ? jQuery(selector + ' option:not(:first)') : jQuery(selector + ' option');
                var arr = options.map(function(_, o) {
                    return {
                        t: jQuery(o).text(),
                        v: o.value,
                        s: jQuery(o).prop('selected')
                    };
                }).get();
                arr.sort(function(o1, o2) {
                    var t1 = o1.t.toLowerCase(),
                        t2 = o2.t.toLowerCase();
                    return t1 > t2 ? 1 : t1 < t2 ? -1 : 0;
                });
                options.each(function(i, o) {
                    o.value = arr[i].v;
                    jQuery(o).text(arr[i].t);
                    if (arr[i].s) {
                        jQuery(o).attr('selected', 'selected').prop('selected', true);
                    } else {
                        jQuery(o).removeAttr('selected');
                        jQuery(o).prop('selected', false);
                    }
                });
            }
            jQuery(document).ready(function() {
                sortSelectOptions('#cf7_id', true);
            });
    
        });
    </script>
    

    5. Go to the code block “Auxiliary” tab in the right and check “Website Backend”

    6. Hit “Save”, and it’s done.

    Obs:
    This solution maintains the select first option in the same position
    I changed the Stack Overflow code in some places from $ to jQuery in order to be compatible with my WP.

    • This reply was modified 6 years, 5 months ago by andre2009. Reason: missing info
    • This reply was modified 6 years, 5 months ago by andre2009.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sort Advanced CF7 Database Form Names in Dropdown’ is closed to new replies.