Typeahead removes field from form #98

Closed
prajwalkman opened this Issue Mar 8, 2013 · 8 comments

Comments

Projects
None yet
2 participants

I have a legacy Rails 2 application which has a form and a text_field_tag. I attached typeahead to the text field, but now that field is no longer included in the form.

Even doing $('form...').serialize() doesn't show the field even though $('input...').val() returns the proper value. What's wrong?

I confirmed that this bug does not appear when typeahead is removed.

I hacked around this by making my field a hidden field, and putting a dummy field for typeahead. I tried to bind the change event to sync its value with my hidden field, but then only the search query was synced. Clearly, typeahead must trigger the change event when it changes the value of the text box.

Right now I hacked around even that issue with focusOut, and it's working now.

Contributor

jharding commented Mar 8, 2013

Can you post the generated HTML?

This is the original HTML that was working:

<input class="tab_general_input typeahead" id="college" name="college" type="text">

And this is the one modified by typeahead:

<input class="tab_general_input typeahead tt-query" id="college" name="college" type="text" dir="auto" autocomplete="off" spellcheck="false">

So, not a simple matter of missing a control name :|

prajwalkman reopened this Mar 10, 2013

Oops sorry for the accidental close. Got confused by the android github client.

Contributor

jharding commented Mar 12, 2013

Sorry, I meant could you post the generated form HTML that you call jQuery#serialize on.

We don't actually call serialize in the code. I just used it from the console to confirm that indeed the form was ignoring the field.
I'll post the form tag's HTML here just in case.

<form action="/some_controller" method="get"></form>

and the submit button's:

<input align="left" button_type="form" class="submit_button" id="submit_button" name="commit" onclick="if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }else { hiddenCommit = document.createElement('input');hiddenCommit.type = 'hidden';hiddenCommit.value = this.value;hiddenCommit.name = this.name;this.form.appendChild(hiddenCommit); }this.setAttribute('originalValue', this.value);this.disabled = true;this.value='Please wait...';result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" type="submit" value="Search">

All this is generated by the form helper in Rails 2.

Contributor

jharding commented Mar 13, 2013

Yeah I have no idea what's causing your problem. You're sure the input that gets turned into a typeahead is a child of the form?

Contributor

jharding commented Mar 14, 2013

I'm going to close this since it seems like this probably isn't an issue with typeahead.js.

jharding closed this Mar 14, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment