Dynamically hiding/showing form fields I have created a custom module in Drupal 8. There should be some fields invisible by default; when a user clicks on More Options, the field should display. When user clicks on Fewer Option, the fields should be hidden again.

How can I achieve this in a Drupal 8 form?
You can easily do this with the Conditional Fields module.


  Conditional Fields allows you to manage sets of dependencies between fields. When a field is “dependent”, it will only be available for editing and displayed if the state of the “dependee” field matches the right condition.
  When editing a node (or any other entity type that supports fields, like users and categories), the dependent fields are dynamically modified with the States API.