0

I have created Auto-complete feature for a text field using JQuery Mobile. It is working and shows the autocomplete suggestions. But the view of the autocomplete list is not what a normal autocomplete list looks like. Here it is what its look like in my case:

enter image description here

Here is the JQuery function:

$(function() {
    $('#project').autocomplete({
        source: "./SearchCustomer.php?term="+document.getElementById("project").value,
        minLength: 0,
        focus: function( event, ui ) {
            $( "#project" ).val( ui.item.label );
            return false;
        },
        select: function (event, ui) {
            $( "#project" ).val( ui.item.label );
            $( "#project-id" ).val( ui.item.value );
            return false;
        }
    })
    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
      return $( "<li>" ).append( "<a>" + item.label + "</a>" ).appendTo( ul );
    };
 });

Here is the HTML:

<label for="name">Customer:</label>
<input type="text" name="project" id="project" value=""  />
<input type="hidden" id="project-id" />
<p id="project-description"></p>

Please help to fix this.

Azeem
  • 2,904
  • 18
  • 54
  • 89

1 Answers1

0

When you programmatically create new elements, you need to trigger the create event to have jquerymobile enhance them.

so it should be something like

.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
    return $( "<li>" ).append( "<a>" + item.label + "</a>" )
                      .appendTo( ul )
                      .trigger( "create" );
};

See this question about injected content in the JQM FAQ.

Ofri Raviv
  • 24,375
  • 3
  • 55
  • 55