Forums Forums Search & Filter Pro Hide a field when i choose an option

Viewing 4 posts - 1 through 4 (of 4 total)
  • Anonymous
    #51682

    Hello, I have a question , I tried to hide a field by choosing an option from a select field, but only do it once, and not do it again when I select another, I have tried with jquery “switch and on change”.

    I have a select with various states of Mexico , when I choose a state , a select field must appear with other cities of that state, but only does the first time i choose a state.

    Example

    $(".sf-field-post-meta-estado .sf-input-select").change(function(){
      var id = $(this).find("option:selected").val();
    
      switch (id){
        case "Nuevo León":
          $('.sf-field-post-meta-coahuila').hide()
          $('.sf-field-post-meta-nuevoleon').show()
          break;
        case "Coahuila":
          $('.sf-field-post-meta-nuevoleon').hide()
          $('.sf-field-post-meta-coahuila').show()
          break;
      }
    });
    

    .sf-field-post-meta-estado .sf-input-select
    is the select field of the states of mexico with options like “Nuevo León, Coahuila”

    .sf-field-post-meta-coahuila, .sf-field-post-meta-coahuila
    These are the city containers of their respective states

    How could I accomplish that?, I think some script is interfering, idk.

    cheers!

    Trevor
    #51699

    Hi

    I am not sure why you are doing it this way?

    Is this search only one post type, and if so, what is that posts type, what taxonomies (including category and tags) and what meta fields does the CPT have?

    Anonymous
    #51761

    its a post, is a filter for a real estate, in the same form i have

    1 – a searchfield
    2 – a sort field
    4 – a meta field (select) with two options (‘rent’, ‘sale’)
    5 – a meta field (select) with all categories (like 9)
    6 – a meta field (select) with the states of mexico (2 options at the moment: nuevo león and coahuila)
    7 – a meta field (checkbox) with the cities of nuevo león state (like 31 options)
    8 – a meta field (checkbox) with the cities of coahuila state (like 20 options)

    9 – a meta field (number) with the range of prices
    10 – a meta field (number) with the range of area

    I would like to accomplish, that when someone select “nuevo leon” only the meta field of the cities of “Nuevo Leon” show, and the meta field of Coahuila hide, and viceversa (its like a “next step” state > city), i’m trying to do this with jquery “if and else or switch case”, but only do that the first time i select one of these.

    thanks for the reply!

    Trevor
    #51791

    Why not have all the cities (7 & 8) in one meta field? If you have auto count enabled and hide empty values, as soon as a state is selected, the cities from the other state disappear.

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