0

I'm trying to use jquery in a form of mine that is rendered via the form api.

How i'm getting jquery to work now is like so

$form['raf_raffle_name'] = array(
    '#type' => "textfield",
    "#prefix" => "<h5>Raffle information</h5><hr>",
    "#title" => "Raffle Name:",
    "#required" => TRUE,
    "#attached" => array(
        'js' => array(
            "$path/jquery.js", "$path/test1.js"
        ),
    )
);

well it works, but i'm not sure if its the right way. Is there a better way? I'm inclined to ask after i saw the 'library' attribute which is supposed to load up certain javascript plugins.

  • Is this Drupal 7 or 8? – cilefen Jan 19 '16 at 15:33
  • This is drupal 7. – Haider Ali Jan 19 '16 at 15:47
2

You should not have to manually include jQuery:

"When JavaScript is added to a page through Drupal, jQuery is automatically added to the page."

-- https://www.drupal.org/node/171213

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.