I looked at this and I seem to be doing the right things that are discussed there. I also looked through the documentation, and I found how I am supposed to add my js file to my Form.
I have run drush cr.
My form is using some AJAX, but I don’t think that should affect this as it is a separate firing js file.
I can see the attached library in the form’s render array ($form[‘#attached’][‘library’][] = ‘mymodule/my_form’;), but the javascript file doesn’t seem to do anything. I am just trying to get it to print to the console at this point.
Here is my mymodule.libraries.yml file:
mymodule.my_form: js: js/form_helper.js: {} dependencies: - core/jquery - core/drupal - core/drupalSettings
Here is my form_helper.js file:
(function ($, Drupal, drupalSettings) { 'use strict'; Drupal.behaviors.wStep = { attach: function (context, settings) { console.log('here'); } }; })(jQuery, Drupal, drupalSettings);
Here is my hook_form_alter attaching the library:
function mymodule_form_alter(&$form, DrupalCoreFormFormStateInterface $form_state, $form_id) { if ($form_id === 'w_form') { $form['#attached']['library'][] = 'mymodule/my_form'; } }