Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete does not display returning data #11

Open
jpcuevas opened this issue Jan 23, 2017 · 3 comments
Open

Autocomplete does not display returning data #11

jpcuevas opened this issue Jan 23, 2017 · 3 comments

Comments

@jpcuevas
Copy link

I was not able to show the data when Its returned from the action result

This is my model

 public class ShiftViewModels
    {
        
        public int ShiftId { get; set; }
        public Vehicle Vehicles { get; set; }
        public int OriginProvId { get; set; }
        public int DestinyProvId { get; set; }

       .......
        public List<Autocomplete> Autocomplete { get; set; }

        public List<ShiftProduct> prdNormal { get; set; }

        public PagedList.IPagedList<ShiftsDetailsViewModels> ShiftDetail { get; set; }

        public IEnumerable<ShiftsDetailsViewModels> Export { get; set; }

    }

public class Autocomplete { public int HelloWorldId { get; set; } public string Message { get; set; } public string Name { get; set; } public int PersonId { get; set; } }

in my view i use
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" }) @Html.AutocompleteFor(model => model.Name, model => model.PersonId, "GetPeople", "Shifts", false,new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })

an thisis my control
public ActionResult GetPeople(string query) { log.Info($"Start"); var res = _repoPass._GetPeopleList(query); log.Info($"res :{res}"); return Json(res, JsonRequestBehavior.AllowGet); }

with console.log in

typehead.mvc.models.js

i can see I can see that my json returns with the data but its not showing

@timdwilson
Copy link
Owner

sorry! I missed your message and haven't checked this project in a while. If this is still an issue, please let me know.

@gate21
Copy link

gate21 commented Sep 19, 2017

I ran into a similar issue, when the autocomplete field is cleared the id value is not set.
I did the following to get around it:
in the typeahead.mvc.model.js
add the following:
}).on('typeahead:change', function (obj) {
onchange(obj);
});
function onchange(obj) {
var obj$ = $(event.target);
var datum = {
id: $('#' + obj$.data("autocomplete-id-field")).val(),
value: event.target.value
};
if (datum.value === "") {
$('#' + jQuery(obj.target).data("autocomplete-id-field")).val("");
}
}

this would ensure that the value id matches the autocomplete.

Let me know if there is a better way.

Regards
Floyd

@timdwilson
Copy link
Owner

timdwilson commented Sep 20, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants