• Resolved ethanpil

    (@ethanpil)


    Thanks for the great plugin its works really well. I am using it on a woocommerce install.

    I was wondering if you could add an auto submit function so that after I select a choice from the dropdown it will automatically load the result instead of me havnig to click the button. The code is quite simple, here is what I did, you can probably make it betetr by adding a checkbox in the admin to choose if the user wnats thins feature…

    In the latest version starting at line 90: The changes on each line are noted with a //<- comment

    $args = array(
    				'show_option_all'    => false,
    				'show_option_none'   => ' ', // <- Added a space to make the first choice blank
    				'orderby'            => $orderby,
    				'order'              => $ascdsc,
    				'show_count'         => $showcount,
    				'hide_empty'         => 1,
    				'child_of'           => $childof,
    				'exclude'            => $exclude,
    				'echo'               => 0, // <- dont output immediately so we can pare it later
    				//'selected'           => 0,
    				'hierarchical'       => $hierarchical,
    				'name'               => $taxonomy_object->query_var,
    				'id'                 => 'lct-widget-'.$tax,
    				//'class'              => 'postform',
    				'depth'              => 0,
    				//'tab_index'          => 0,
    				'taxonomy'           => $tax,
    				'hide_if_empty'      => true,
    				'walker'			=> new lctwidget_Taxonomy_Dropdown_Walker()
    			);
    			echo '<form action="'. get_bloginfo('url'). '" method="get">';
    			$select = wp_dropdown_categories($args); //<- store in var
    			$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select); //<- add the javascript to submit on change
    			echo $select;  //<- output the select
    			//<-- hide the submit button echo '<input type="submit" value="go &raquo;" /></form>';
    		}

    https://www.ads-software.com/plugins/list-custom-taxonomy-widget/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Nick Halsey

    (@celloexpressions)

    Thanks for the submission. Unfortunately, auto-submitting dropdowns are not keyboard-accessible, so their use (despite being frequent and nice for most users) is generally discouraged. Feel free to fork the plugin with this feature, though!

    Nick, I understand your accessibility concern and applaud your acceptance of a non-accessible fork ??

    Ethan, thanks for sharing, just made my day!

    By the way, when you hide the submit button

    //<-- hide the submit button echo '<input type="submit" value="go ?" /></form>';

    you’ll still want to echo the closing form tag somewhere.

    Just stumbled upon this since I had several taxonomy widgets in the sidebar and they would submit all at once…

    Or you could just echo the submit button wrapped in noscript to hide it

    echo '<noscript><input type="submit" value="go ?" /></noscript></form>'; // <- show button for noscript

    as seen on https://codex.www.ads-software.com/Function_Reference/wp_dropdown_categories

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Code Submission: Submit on dropdown select’ is closed to new replies.