1

this was already asked here Handling id from autocomplete field

but still without answer: I have an autocomplete field which uses geonames query to search cities. After value is selected I want the city name and admin area to fill into the autocomplete field, and to fill geoname_id of selected value into another (hidden) field. I don't want the geoname_id to be visible - it looks kind of ugly...

I've tried to hack the autocomplete.js and added following line

$("#search-geoname-id").val($(this.selected).data('autocompleteValue'));

into Drupal.jsAC.prototype.hidePopup function

then also tried

$("input[id=search-geoname-id]").val($(this.selected).data('autocompleteValue'));

but both without effect :/

Thanks for your help, Tomas

1
  • You should cut the solution out of your question and post it as an answer, using the option Answer your own question. This is not only acceptable, but encouraged. Commented May 21, 2014 at 12:07

1 Answer 1

3

I've found solution, so I'll share it with others:

Both options in the question were correct. I just expected that the new value of hidden field will be visible through "see source code" which it's not. When I check the $form_state['values']['geonameid'] it is filled correctly.

The complete solution:

1) In Drupal.jsAC.prototype.found I've filled the 'autocompleteValue' with value instead of key, and added new data 'autocompleteKey' which I've filled with key, surprisingly :)

2) In Drupal.jsAC.prototype.hidePopup just added $('input[id="search-geoname-id"]').val($(this.selected).data('autocompleteKey'));

Hope this helps to someone in future.

P.S. I know modifying core functions is not the cleanest way to do things, but it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.