How do I add a JavaScript file from a module? $form['set_end_date'] = array (
  '#type' =&gt; 'date',
  '#title' =&gt; t('set end date'),
  '#required' =&gt; TRUE,
);

$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; $this-&gt;t('Fetch'),
  '#button_type' =&gt; 'primary',
);
return $form;


How do I add a JavaScript file from a module?
You will have to add the js in libraries.yml, like


dirty_forms:
  version: VERSION
  js:
    js/jquery.dirtyforms.js:{}
dirty_forms_ckeditor:
  version: VERSION
  js:
    js/jquery.dirtyforms.ckeditor.js:{}


and then include in the form via

$form['#attached']['library'][] = 'dirty_forms/dirty_forms';