How do I pass an extra parameter to Jquery Autocomplete field?

前端 未结 8 1424
情书的邮戳
情书的邮戳 2020-12-08 12:41

I\'m using the JQuery Autocomplete in one of my forms.

The basic form selects products from my database. This works great, but I\'d like to further develop so that o

相关标签:
8条回答
  • 2020-12-08 13:24

    This work for me. Override the event search:

    jQuery('#Distribuidor_provincia_nombre').autocomplete({
        'minLength':0,
        'search':function(event,ui){
            var newUrl="/conf/general/provincias?pais="+$("#Distribuidor_pais_id").val();
            $(this).autocomplete("option","source",newUrl)
        },
        'source':[]
    });
    
    0 讨论(0)
  • 2020-12-08 13:26
    $('#txtCropname').autocomplete('Handler/CropSearch.ashx', {
        extraParams: {
            test: 'new'
        }
    });
    
    0 讨论(0)
  • 2020-12-08 13:27

    I believe you are correct in thinking your call to $("#product").autocomplete is firing on page load. Perhaps you can assign an onchange() handler to the select menu:

    $("#zipcode").change(resetAutocomplete);
    

    and have it invalidate the #product autocomplete() call and create a new one.

    function resetAutocomplete() {
        $("#product").autocomplete("destroy");
        $("#product").autocomplete({
             source:"product_auto_complete.php?postcode=" + $('#zipcode').val(),
             minLength: 2,
             select: function(event, ui){... }
        });
    }
    

    You may want your resetAutocomplete() call to be a little smarter -- like checking if the zip code actually differs from the last value -- to save a few server calls.

    0 讨论(0)
  • 2020-12-08 13:29

    Hope this one will help someone:

    $("#txt_venuename").autocomplete({
        source: function(request, response) {
        $.getJSON('<?php echo base_url(); ?>admin/venue/venues_autocomplete', 
            { 
                user_id: <?php echo $user_param_id; ?>, 
                term: request.term 
            }, 
          response);
        },
        minLength: 3,
        select: function (a, b) {            
            var selected_venue_id = b.item.v_id;
            var selected_venue_name = b.item.label;            
            $("#h_venueid").val(selected_venue_id);
            console.log(selected_venue_id);            
        }
    });
    

    The default 'term' will be replaced by the new parameters list, so you will require to add again.

    0 讨论(0)
  • 2020-12-08 13:36

    You need to use a different approach for the source call, like this:

    $("#product").autocomplete({
      source: function(request, response) {
        $.getJSON("product_auto_complete.php", { postcode: $('#zipcode').val() }, 
                  response);
      },
      minLength: 2,
      select: function(event, ui){
        //action
      }
    });
    

    This format lets you pass whatever the value is when it's run, as opposed to when it's bound.

    0 讨论(0)
  • 2020-12-08 13:39
    jQuery("#whatJob").autocomplete(ajaxURL,{
        width: 260,
        matchContains: true,
        selectFirst: false,
        minChars: 2,
        extraParams: {  //to pass extra parameter in ajax file.
            "auto_dealer": "yes",
        },
    });
    
    0 讨论(0)
提交回复
热议问题