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

jQuery error setting the ID field when item is selected #6

Open
DiskJunky opened this issue Mar 16, 2016 · 7 comments
Open

jQuery error setting the ID field when item is selected #6

DiskJunky opened this issue Mar 16, 2016 · 7 comments

Comments

@DiskJunky
Copy link

There is a jQuery error when selecting an item returned from the typeahead query. It is unable to parse the complex value of "data-autocomplete-id-field".

Fix: Change typeahead.mvc.model.js, line 41 from;
$('#' + jQuery(obj.target).data("autocomplete-id-field")).val(datum.id.toString());
to
$(obj.target).siblings("input[type='text'].tt-hint:first").val(datum.id.toString());

It's worth noting that even if jQuery could parse the value, it still wouldn't work as the input field storing the ID from the returned results doesn't actually have a HTML id set.

@timdwilson
Copy link
Owner

Please send me the source code where this is failing so I can reproduce this issue. Thanks very much. Which version of jQuery are you using?

@DiskJunky
Copy link
Author

I'm using jQuery 1.10.2, the same as your sample application.

I've done a little digging into this and it may have something to do with the complexity of how I was rendering the model. Specifically, the item I want to have a type ahead on is on "Model.Journey[i].CIty". This renders an autocomplete-id-field value of _Page_Views_Home__Journeys_cshtml)_Model_Journeys_get_Item(value(ASP__Page_Views_Home__Journeys_cshtml+<>c__DisplayClass2)_i)_CityID rather than the more simplified "PersonId" value in the example app.

Model annotations;
[Display(ResourceType = typeof(General), Name = "Register_Label_City")] [StringLength(250, ErrorMessageResourceType = typeof(General), ErrorMessageResourceName = "StringLengthAttribute_InvalidMaxLength")] public string CityName { get; set; }
Rendered in partial view as;
<div class="form-group"> @Html.LabelFor(m => Model.Journeys[i].City, new { @class = labelClass }) <div class="@controlContainerClass"> @Html.AutocompleteFor(m => Model.Journeys[i].CityName, m => Model.Journeys[i].CityID, "GetCities", "Home", false, new { htmlAttributes = new { @class = controlClass } }) </div> </div>

@timdwilson
Copy link
Owner

Yes I have never tested this using a property off of an item in a collection which looks to be the problem here. If you do not mind, can you please send me your view, the model class and controller so I can test (basically enough code so I can drop it into a project and recreate what you are doing)? Thanks in advance and I appreciate you putting in an issue so that others who use this library may benefit.

@DiskJunky
Copy link
Author

See attached for a basic working sample outlining the autocomplete-id-field issue. Text search is case sensitive.
TypeaheadSample.zip

@timdwilson
Copy link
Owner

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

@DiskJunky
Copy link
Author

No worries. Still an issue though we worked around it in the end

@timdwilson
Copy link
Owner

timdwilson commented Sep 15, 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

2 participants