Reputation: 4265
I try to make a autocomplete input with jquery mobile. '
So I found a demo for this here: http://demos.jquerymobile.com/1.4.0/listview-autocomplete-remote/
But my problem is, that I cant change the value of the input field by clicking on a listed entry.
I want that if I click on a listed entry the value of the input field gets the value of the entry like the normal autocomplete behavior.
Here is a SSCCE (I couldnt bring the page to work on jsfiddle so I used pastebin):
Thanks for any help
Upvotes: 2
Views: 3194
Reputation: 31732
It is more or less the same as in this link.
In your code, you're using .ready()
and not attaching click
event to dynamically generated li
. .ready()
isn't recommended to be used in jQM, instead, use jQuery Mobile 1.4 events.
The equivalent event to .ready()
is pagecreate
as it replaces pageinit
in jQM 1.3.2 and below.
$(document).on("pagecreate", "#startseite", function () {
/* retrieve text from clicked li */
$(document).on("click", "li", function () {
var text = $(this).text();
$(this).closest("ul").prev("form").find("input").val(text);
});
$("#autocomplete").on("filterablebeforefilter", function (e, data) {
/* rest of code */
});
});
Upvotes: 4