0

After scouring the www for a solution, I thought I'd post my question here. I've got an autocomplete textfield that's actually retrieving custom URLs from the taxonomy_term_data and field_data_cip_title (custom field for one of my taxonomy vocabularies) tables. Here's the script that I'm using to create the custom URLs:

SELECT CONCAT('<a href=\"/college/disciplines/check?eid=', ttd.tid, '\">', ttd.name, ': ', fdct.cip_title_value, '</a>') cip
  FROM {taxonomy_term_data} ttd,
       {field_data_cip_title} fdct
 WHERE ttd.tid = fdct.entity_id
   AND fdct.entity_type = 'taxonomy_term'
   AND fdct.bundle = 'cipcodes2010'
   AND fdct.deleted = 0
   AND LENGTH(ttd.name) = 7
   AND CONCAT(ttd.name,fdct.cip_title_value) LIKE :string
 LIMIT 0, 7", array(':string' => '%' . $string . '%')

The URLs appear just fine in the autocomplete textfield, and clicking on one of them will take you to the correct URL.

However, when clicking on a link, the HTML of the link appears in the textfield for a brief moment prior to being taken to the URL:

<a href="/college/disciplines/check?eid=5373">01.1202: Soil Chemistry and Physics.</a>

which is quite unattractive. Also, if the user uses the arrow keys to navigate to the desired choice, and then hits the enter key, nothing happens other than the selected HTML appearing in the textfield.

Is there a better way to return clickable - or selectable via arrow keys - autocomplete results that can be acted upon?

Please let me know if I need to elaborate a bit more, and I'd be more than happy to do so.

1 Answer 1

1

I suspect that what you are looking to do is identical to what the API module does on http://api.drupal.org/api/drupal . Based on a quick look, the module does not appear to construct the URL and return it along with the autocomplete values. Instead, it returns the best matches and when a match is clicked (or selected via the keyboard), it simply submits the form along with the selected value. The form redirects the user appropriately.

Check the block hook as well as the api_search_form functions in api.module to see how this is done. The module's repository might also prove useful, especially api.js.

1
  • coleopterist: Yes, the api.drupal.org/api/drupal demo is precisely the functionality that I'm trying to mimic. Thanks for pointing to that as a good starting point.
    – cmmsites
    Commented Jul 5, 2012 at 20:06

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.