Forums › Forums › Search & Filter Pro › update filter element through javascript?
- This topic has 18 replies, 3 voices, and was last updated 7 years, 11 months ago by Anonymous.
-
Ross Moderator(Private) December 1, 2016 at 11:03 am #73431
Hey Ash
I’ve not tried to do what you are doing exactly but in theory it should work.
So you want to clear one field if the other field is updated?
I think what you are doing is fine, setting
.val("")
.. when doing this, do you see the field itself change value? If so, then all you should need to do is submit the form (which will handle the building of the new URL) –$('.searchandfilter').submit();
– this will also work for an ajax powered search form.What you suggested above also sounds like it might do the trick (triggering a change event after you have set the val), you might need to trigger
input
orchange
and then you would need to do it here in your example:jQuery('.sf-field-taxonomy-taxonomy1 select').on('change',function(){ jQuery('.sf-field-taxonomy-taxonomy2 select').val('').trigger('change'); });
Our next major version has quite a large rewrite and will include a JS api for doing this kind of thing much more easily.
Hope that helps
Anonymous(Private) December 1, 2016 at 9:06 pm #73526So far only this method worked.
jQuery(document).on("sf:ajaxstart", ".searchandfilter", function(){ var tax1 = jQuery('.sf-field-taxonomy-tax1 select').val(); if(location.search.search('_sft_tax1='+tax1) == -1){ jQuery('.sf-field-taxonomy-tax2 select').val(''); } });
(edited by @trevorsf to add code tags to the code)
Ross Moderator(Private) December 3, 2016 at 1:09 pm #73814Hey again Ash
I will do some more tests next week on this and if there is a better way of doing this I will share with you. As mentioned though, this all needs a bit of a rework and I won’t be making any changes to this area of the plugin until the next major version where there will be an API to make all this super easy.
Thanks
-
AuthorPosts