Forums › Forums › Search & Filter Pro › Default option on load
Tagged: default option, page load, preselected
- This topic has 8 replies, 2 voices, and was last updated 7 years, 11 months ago by Trevor.
-
Anonymous(Private) December 14, 2016 at 6:26 am #76116
Hi Guys,
Great plugin 🙂
QQ – is there a way to set a taxonomy dropdown to have a default option showing those matching results on page load (i.e a preselected option)? Critical piece of this site.
Is there a gist out there already I can use or work with before hitting the code deck (assuming someone else would have done this? Something that hooks into the $input_object I’m assuming?
Thank you!
Trevor(Private) December 14, 2016 at 12:31 pm #76149Yes is the answer, using our sf_edit_query_args filter.
There are many examples of usage also post here on the forum, a key term search for that filter name should yield some.
Anonymous(Private) December 14, 2016 at 2:40 pm #76187Hey Trevor,
Thank you.
After numerous other options I tried the below but not sure I’m in the right zone (the custom class is added to the field so it’s partly working).
I just want to pull one of the options from that dropdown as the default on that page (selected option on page load).
Any pointers?
Thank you!
<?php function filter_input_object($input_object, $sfid) {
if ($input_object[‘name’] == ‘_sft_testcat’) {
$input_object[‘defaults’] = array(“Test”);
$input_object[‘attributes’][‘class’] = ‘mynew_class’;
}return $input_object;
}
add_filter(‘sf_input_object_pre’, ‘filter_input_object’, 10, 2); ?>Anonymous(Private) December 15, 2016 at 1:49 am #76423I have tried numerous ways to do this without much luck including the function above, a standard jquery function and functions (init & ajax finish) on ajax finish load (as per Q1 here – https://www.designsandcode.com/wordpress-plugins/search-filter-pro/faqs/).
Ideally I’d love to just set one of the dropdown options as the selected value (either when the page loads or when the other dropdown is clicked – this one I’m setting it on is hidden).
More than happy to do it via $(“select option[value=’test’]”).attr(“selected”,”selected”);
I just need to get that working in a place it executes on the page!
The page with the form is a single-taxonomy.php and has 2 taxonomy dropdown on it (one that the user sees and one that’s hidden that I’d like to set the taxonomy term on). This all works correctly if both dropdown are visible and the user selects the term – so it’s just figuring out how to set the term on the hidden dropdown when the page loads or when the user clicks on the available taxonomy dropdown to them (i’ve tried an on change event without luck).
-
AuthorPosts