0
$form['set_end_date'] = array (
  '#type' => 'date',
  '#title' => t('set end date'),
  '#required' => TRUE,
);

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

How do I add a JavaScript file from a module?

  • are you using drupal 7 or 8? – Japo Domingo Mar 27 '17 at 21:33
2

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';

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.