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

Class attributes are not applied from AutocompleteFor() #5

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

Class attributes are not applied from AutocompleteFor() #5

DiskJunky opened this issue Mar 15, 2016 · 7 comments

Comments

@DiskJunky
Copy link

To reproduce: Use @Html.AutocompleteFor() in a view to render the typeahead, setting the last parameter to
new { htmlAttributes = new { @class = "form-control" } }

Result: Typeahead is rendered with class "typeahead tt-input" but no "form-control".

Note: this occurs in the sample application in the documentation.

Fix (for me anyway) via jQuery;

function FixTypeaheadStyling() {
    var typeaheads = $("input[type='text'].tt-input");
    typeaheads.removeClass("tt-input").addClass("form-control");
    typeaheads.parent('span.twitter-typeahead').css('display', 'block');
}
@timdwilson
Copy link
Owner

Hi there, are you using the latest version of AutocompleteFor? I added in the functionality you are requesting in the latest version. You can see in the Wiki on this site that my tests show this works. If you have a test where this is failing, can you please send me the source code? Thanks

@DiskJunky
Copy link
Author

I'm using via NuGet;
Typeahead.js: 0.10.5
Typeahead.js for MVC 5: 1.1.2
Typeahead.js for MVC 5 Models: 1.0.7

I've verified that the specified class is not appearing in your sample web application as of 15/03/2016 12:00 GMT. I haven't tried running your unit tests but given that I'm seeing the same behavior in both the sample app and my own it would seem that there's a bug there. Unit tests are all very well but sometime an issue appears only when you actually go and try it :)

Generated output by right-clicking the Name field in Chrome;
<input class="typeahead tt-hint" data-autocomplete-id-field="PersonId" data-autocomplete-url="/HelloWorld/GetPeople" data_autocomplete_url="/HelloWorld/GetPeople" type="text" value="" readonly="" autocomplete="off" spellcheck="false" tabindex="-1" style="position: absolute; top: 0px; left: 0px; border-color: transparent; box-shadow: none; opacity: 1; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);">
<input class="typeahead tt-input" data-autocomplete-id-field="PersonId" data-autocomplete-url="/HelloWorld/GetPeople" data_autocomplete_url="/HelloWorld/GetPeople" id="Name" name="Name" type="text" value="" autocomplete="off" spellcheck="false" dir="auto" style="position: relative; vertical-align: top; background-color: transparent;">

As you can see: no class attribute specified with "form-control"

@timdwilson
Copy link
Owner

Thank you for your detailed response :) I will take a look.

@mnbob70
Copy link

mnbob70 commented Apr 28, 2016

The issue is on line 102 of HtmlHelpers.
if (!((IDictionary<string, object>) htmlAttributes).ContainsKey("@Class"))
should be
if (!((IDictionary<string, object>) htmlAttributes).ContainsKey("class"))

@timdwilson
Copy link
Owner

Can you make the change and issue a pull request?

Sent from my iPhone

On Apr 28, 2016, at 1:40 PM, Bob Hanson notifications@github.com wrote:

The issue is on line 102 of HtmlHelpers.
if (!((IDictionary) htmlAttributes).ContainsKey("@Class"))
should be
if (!((IDictionary) htmlAttributes).ContainsKey("class"))


You are receiving this because you commented.
Reply to this email directly or view it on GitHub

@peterdew
Copy link
Collaborator

peterdew commented Sep 19, 2017

@mnbob70 that was totally correct Bob, but this code is changed by the recent merge from Groblerf. I'll test this issue against the new code asap

@timdwilson
Copy link
Owner

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

4 participants