JQuery autocomplete how to write label in autocomplete text input?

前端 未结 5 1916
花落未央
花落未央 2020-12-18 05:57

Hello I am using jQuery UI autocomplete.

I am getting values and labels from the drop down area. I will write the value in a hidden input and use it later. I could d

5条回答
  •  攒了一身酷
    2020-12-18 06:13

    Following is my code where i use desc from autocomplete to fill into next element that is an hidden input box :

    Check if this helps you in something

    function getTage() {
    var availableTags = [
        {assign var=result_products_cnt value=1}
        {foreach from=$result_products item=product}
            {if $result_products_cnt eq $result_products_total}
                { label: "{$product.name}", value: "{$product.name}", desc: "{$product.id_product}" }
            {else}
                { label: "{$product.name}", value: "{$product.name}", desc: "{$product.id_product}" },
            {/if}
            {assign var=result_products_cnt value=$result_products_cnt+1}
        {/foreach}
    ];
    return availableTags;
    }
    var availableTags = getTage();
    $( "#nxpublisher_productid_"+i ).autocomplete({
      source: availableTags,
      select: function( event, ui ) {
        $(this).next().val(ui.item.desc);
      },
      open: function() { $('.ui-menu').width(400); $('.ui-menu li a').css("font-weight", "bold"); $('.ui-menu li a').css("text-align", "left");}
    });
    

    nxpublisher_productid_ is one of the id of my multiple taxtboxes where i want to initiate autocomplete.

    P.S i have used this function in smarty so please dont mind copying complete function.

提交回复
热议问题