0

The text field that is created seems to just act like a normal textfield, no autocomplete function or any indication that it works at all.

There's no errors in the console. I've run checks to see if jQuery UI is loading, it is. I'm using jQuery Update module, so both libraries are at version 1.10.

I'm using the Bootstrap theme, but I've tried disabling that and using Bartik, it makes no difference.

Any ideas?

Here's the form alter function I'm using in my module. It fires just fine.

function mymodule_form_mymodule_form_newlead_alter (&$form, &$form_state) {

    $form['business_category'] = array(
        '#title' => t('Business Category'),
        '#description' => t('Category' ),
        '#type' => 'textfield',
        '#id' => 'business_category',
        '#attached' => array(
            'library' => array(
                array('system', 'ui.autocomplete'),
            ),
            'js' => array(
                drupal_get_path('module', 'mymodule') . "/custom.js",
            ),
        ),
    );

}

Here's custom.js

(function ($) {

        $( "#business_category" ).autocomplete({
            source: [ "cat1", "cat2", "cat3" ]
        });

})(jQuery);
  • Are u sure that '#id' is setting the id on the textfield correctly? Also, you should probably using drupal behaviors for your js. – 2pha Dec 9 '14 at 4:49
0

Adding drupal behaviours, as suggested by @2pha, did the trick:

(function ($) {
    Drupal.behaviors.infiniteScrollAddClass = {
        attach: function (context, settings) {

            $( "#business_category" ).autocomplete({
                source: [ "cat1", "cat2", "cat3" ]
            });
        }
    }

})(jQuery);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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