I am trying to write a custom module in Drupal 8 to populate a taxonomy field (release_decade) based on information in another field (release_date) for a custom content type in order to create an exposed dropdown filter in a view.

I am using hook_form_FORM_ID_alter & have tried attaching JS as suggested in autofilling-fields-based-on-another-field but the script does not seem to run & most of the other examples seem to cover Drupal 7.

Does anyone have any Drupal 8 specific suggestions for either: a) Autofilling a taxonomy field based on other content fields? b) Automatically assigning a taxonomy item to a hidden property when an entity is created?

Or am I going about this completely the wrong way?

  • Can you give us a little more context? Is this a block plugin, or a form controller?
    – Amy
    Feb 13, 2017 at 16:36
  • Also can you display some of your attempted code?
    – Amy
    Feb 13, 2017 at 16:37
  • It seems like this is more JavaScript question than Drupal question.
    – Eyal
    Feb 14, 2017 at 0:20
  • None of the code I have attempted so far as actually had any effect & I am unsure if I am going about this in the right way. I am trying to use function <module_name>_form_node_article_form_alter(&$form, FormStateInterface $form_state, $form_id) to attach a Javascript file to a form. Is this possible? Feb 15, 2017 at 9:01


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.