Forums › Forums › Search & Filter Pro › jQuery file "Return False" breaking S&F
- This topic has 6 replies, 2 voices, and was last updated 9 years, 6 months ago by
Anonymous.
-
Anonymous(Private) September 16, 2016 at 7:02 pm #58500
Hi,
I’m trying to get the value of selected options in my jquery file to dynamically show/hide content on the page. Here’s my code:
jQuery(document).ready(function() { var inputbtn = jQuery('.sf-field-submit').children('input'); jQuery(inputbtn).on('click', function() { var selectedItem = jQuery('.sf-input-select option:selected').text(); console.log(selectedItem) return false; }) });When I remove the return false; for my on.click function, it will only console.log out the first option clicked. After that, if I select another option and press “submit” it will not console.log it.
When I add the return false, it works indefinitely — but it breaks S&F and does no longer display new results in my results.php file.
Any idea what I’m doing wrong here?
Trevor(Private) September 20, 2016 at 6:43 pm #59073So, what you should be doing is using jQuery to monitor the value of the field and when it changes use the show attribute to reveal a previous hidden div. It would greatly depend on what it is that you are monitoring for changes. Is it a field with a fixed number of options? Or one whose options will be change by the site user from time to time?
Anonymous(Private) September 23, 2016 at 2:16 pm #59738It is a S&F field SELECT box with a set number of OPTIONS…..The options will never change, but the “selected” one will change based on what they select.
I’m trying to grab the value of the selected option when they click on the “submit”.
The classes in S&F are weird which is why you see me grabbing the submit button with my variable “inputbtn”.
So, I think I’m doing what you’re telling me to do, but it doesn’t seem to be working.
Trevor(Private) September 23, 2016 at 2:21 pm #59742Ok, without the return false it works OK but only once?
If so, make you code a function instead and then call THAT with the ready function. Then, use this code to detect if S&F has performed its ajax and call the function you made again?
$(document).on("sf:ajaxfinish", ".searchandfilter", function(){ console.log("ajax complete"); //so load your function here again });Maybe?
-
AuthorPosts