I have a simple autocomplete test which works with hard coded data.
However when i add my own data (which contains over 1000 data) it doesn't work and only shows the first letter, so if my data is "Apple"
when i type B - it shows Banana but i cannot type "BA" as the "A" disappears.
I was expecting that i can write the whole word rather than the first letter.
This is the working code:
var validOptions = ["Bold", "Normal", "Default", "100", "200"]
previousValue = "";
$('#ac').autocomplete({
autoFocus: true,
source: validOptions
})
.keyup(function() {
var isValid = false;
for (i in validOptions) {
if (validOptions[i].toLowerCase().match(this.value.toLowerCase())) {
isValid = true;
}
}
if (!isValid) {
this.value = previousValue
} else {
previousValue = this.value;
}
});
So these letters: Bold", "Normal", "Default", "100", "200" work. BUT
As soon as i change the validOptions to:
var validOptions ='@Url.Action("SerialProdNumStockSiteAutoComplete", "Ajax")?stocksitenum=LW&model=' + $("#Form_Prod_Num").val();
It doesn't work as it should.
is there another way to do this, or do you know where i'm going wrong.
This question is about an alternative to .keyup
SerialProdNumStockSiteAutoComplete code:
public JsonResult SerialProdNumStockSiteAutoComplete(string term,string stocksitenum,string model)
{
return Json(AutoComplete.DeviceFromStockSite(term, stocksitenum, model), JsonRequestBehavior.AllowGet);
}
Device from stock:
public static List<string> DeviceFromStockSite(string term, string stocksitenum, string model)
{
//devices will always come from serialised stock
var qryStock =
SC42Ctx.SPNlocs
.Where(x => x.Nloc_Site_Num.StartsWith(stocksitenum)
&& x.Nloc_Part_Num == model
&& x.Nloc_Ord_Num == null)
.Select(
s =>
new TicketSerialNumber
{
SerialNumber = s.Nloc_ID_Num,
Source = stocksitenum,
Call = s.Nloc_Ord_Num.ToString()
})
.ToList();
When i copy the URL this shows:
This was when i entered 4 and couldnt add anything else
SerialProdNumStockSiteAutoComplete
method code ? – Vehemence@Html.Action
not@Url.Action
– Karli