Mandatory dropdown filter enable the search

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Mandatory dropdown filter enable the search

This topic contains 8 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 2 years, 7 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #25092
    danielecelsa07
    danielecelsa07
    Participant

    Hello, I bought your Ajax search pro and I think is amazing, but I’ve some doubts that I would need help for.
    I’ve a custom post type called “Dishes”, to every dish I’ve associated different taxonomies, in particular the taxonomy terms that the dish belong to, for example “Meat”, “Fish” (the name of taxonomy is “kind of meal”).

    Then, I’ve an other taxonomy called “City”. Every dish has an association with the taxonomy term belonging to the “City” taxonomy, for example “New York” “London”.

    So every dish, for example “Hamburger” has an association with a “kind of meal” and with a “City”, so Pizza has a relation with “Meat” and “London”.

    Said that, I want a search bar where people can type the taxonomy terms belonging to the “kind of meal” taxonomy AND at the same time, a drop down menu with inside all the “City”.
    I tried this and it’s working great.
    BUT, I need to enable the search form ONLY if the drop down menu has at least a valid selection (the name of a City).
    If someone try to perform a search without selecting a city from the dropdown menu, I would like message in the frontend that say something like “please select the city before to perform the research”.
    Actually it means the filter is mandatory to the search.

    I hope I was clear with my explanation, thank you in advance for your help.

    Cheers,
    Daniele

    #25112
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Daniele,

    At this point, this is only possible via customizations unfortunately. There is a “required” field feature in development for custom field filters, it should be available for the taxonomy filters as well in the next few releases.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #25121
    danielecelsa07
    danielecelsa07
    Participant

    Hi Ernest,

    thanks for your kind and quick answer!

    So:
    1) You said: the “required” field feature for custom field filter is in development -> Do you have an estimated time for this feature to be available to the public?
    2) What about the same feature for taxonomy filters, do you also have an estimated time for the new releases to be available to the public?
    Or maybe I misunderstood and both features (“required” field for custom field filters and for taxonomy filters) will come together with new releases?
    3) this is only possible via customizations unfortunately -> Can you please suggest me some guide, link to some article, something that can explain me how to put this customization into practice? Or maybe just the lines of code that I should use, and where exactly to use them?

    Sorry if I ask with insistence, but this feature is very very important on my website, I would really need it.

    Thank you very much in advance.
    Regards,
    Daniele

    #25124
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    1 & 2 – A next patch is out within 48 hours, this feature is planned for the one after that. You can follow the public development log here: https://trello.com/b/BUNOEob3/asp
    The patch that should contain this feature is planned for 14th of January.

    3. Well, that is a bit difficult to explain, as it may require modifications in multiple files. I might be able to suggest a very basic solution to start off. I have constructed a custom code, that should prevent the trigger unless there is a non-empty selection.
    Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

    add_action('wp_footer', 'asp_custom_script', 9999999);
    function asp_custom_script() {
      ?>
      <script>
      jQuery(function($){
        $('.asp_w form fieldset select').off();
        $('.asp_w form fieldset select').on('change', function(e){
          if ( $(this).val() != -1 && $(this).val() != 0 && $(this).val() != '' ) {
            var $c = $(this).closest('.asp_w');
            var id = $c.data('id');
            var instance = $c.data('instance');
            ASP.api(id, instance, 'searchFor'); 
          }
        });
      });
      </script>
      <?php
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #25140
    danielecelsa07
    danielecelsa07
    Participant

    Hi Ernest,

    thank you for your kind reply, we really appreciated you wrote a custom code just for us 🙂

    Anyway, we tried your code but it does not seem to be working for us.
    What I got from your reply is that, using your code, the button trigger in the search bar should be ‘deactivated’ (which means you cannot search anything, you cannot ‘click’ the button) if no selection is checked in a dropdown menu or in a checkbox menu (I tried both) of a Taxonomy filter.
    The trigger should become ‘active’ (which means that it allows searching something, the button is clickable) when I make at least a selection in the dropdown/checkbox menu of the Taxonomy filter.

    Is this the expected behavior?
    If yes, maybe I got something wrong in the settings of the filter.

    Anyway, what I did it is just copy&paste your code in function.php file at the beginning of the file, right below <?php

    Here it is a page where we tried your code, just in case you would want to take a look:
    https://www.idlike.app

    Attached you can find the setting for the Taxonomy filter.

    Thanks in advance!
    Daniele

    Attachments:
    You must be logged in to view attached files.
    #25147
    danielecelsa07
    danielecelsa07
    Participant

    Hi again,

    waiting for your kind reply, we noticed that something changed (not sure if as a consequence of trying your code) in the URL when performing a search.

    Anything I search, the result page URL is something like in the screenshot attached, instead of …./?s=searched_term

    Could you please help to change the URL result as it was before?

    Thanks!
    Daniele

    Attachments:
    You must be logged in to view attached files.
    #25161
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    That simple code only prevents the facet change trigger, when a change is made to the drop-downs, unless the value is different from the default ones. For more complicated solutions I’m afraid you will have to contact a developer.

    That URL looks correct, that happens, when the search override is active, and the default “GET” method is used. If you prefer not to see that information, you can change that to the “POST” method.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #25168
    danielecelsa07
    danielecelsa07
    Participant

    Hi Ernest,

    thanks again for your kind reply.

    Just a question, you told me about the 14th January new Release. In this release, will the feature that we need be added? I mean the chance to have the button search ‘deactivated’ unless a selection is done in the filter.

    If not, are you planning to add this feature in some future release? All our idea is relying on your search bar, and without that our website is crap…:)
    So we are willing to wait for your release, but if you are not sure if/when you will release that fix, we will maybe contact some developer.

    Thank you in advance,
    Domenico

    #25184
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Domenico,

    Something similar to that should be added – the button actions will be prevented until a valid selection, I am almost sure that by disabling that button.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.