2

Well I have created a JS to validate a form, and when I try to attach the hook in my custom module the JS its not showing. My custom module it's call "ajax_form"

My ajax_form.libraries.yml

ajax_form:
  version: 1
  js:
    js/ajax_form.js: {}
  dependencies:
      - core/jquery

My ajax_form.module

<?php
function ajax_form_page_attachments(array &$attachments) {
    $attachments['#attached']['library'][] = 'ajax_form/ajax_form';
}

I have a console.log('test'); in the first line of my JS but this is not displaying.

I have run out of ideas of what it be. Also I'm new to Drupal maybe is that.

1
  • 1
    verify ajax_form is your module name it should be in YOUR_MODULE_NAME/YOUR_LIBRARY_NAME eg: $attachments['#attached']['library'][] = 'YOUR_MODULE_NAME/ajax_form'; May 13, 2018 at 7:21

1 Answer 1

3

Just wrong indentation. Dependencies need two spaces indentation:

ajax_form:
  version: 1
  js:
    js/ajax_form.js: {}
  dependencies:
    - core/jquery

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.