开发者

Autocomplete without using a callback

I want to use autocomplete-fields that link to an external source for their autocomplete-data. Drupal seems to refuse all autocomplete_paths that are not reachable within Drupal. Any ideas how to circumvent that problem? The form field looks like that:

$form['business_city'] = array(
    '#type' => 'textfield',
    '#size' => 30,
    '#title' => t('city'),
    '#autocomplete_path' => '_/city?=',
    '#default_value' => $userProfile->field_address_business_city[0]['v开发者_运维问答alue'],
);

_/city is not reachable within Drupal for performance reasons. The script bootstraps Drupal up to session-level to check for a valid login.

UPDATE:

If I create an autcomplete-field by attaching the needed markup manually to the field it works but it is awkward to maintain:

'#attributes' => array('class' => 'form-autocomplete'),
'#suffix' => '<input type="hidden" disabled="disabled" value="/_/city?n=" id="edit-private-city-autocomplete" class="autocomplete">',


Instead of hacking, you could make sure that the path you are querying "/_/city?n=" is a valid menu_hook item. That way it will validate against the drupal_valid_path() inside theme_textfield(). From within the menu hook function callback you could then forward the request to your external data source.


Drupal 6 validates in theme_textfield() if the autocomplete path is a valid (internal) path.

So, you can't work around this unless you override that theme function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜