I have two custom content types.

  1. Comic books borrowed, as an application form to borrow comics
  2. Available comic books and their respective available issues

My goal is to have the website editors record each comics with available issues (each having different issues, this is collected with a simple text field and any issue field can be added to a comicbook). The other, Application form is for (registered) site visitors wanting to borrow the comic books.

I would like to have the application form to be able to refer a comic and dynamically load their respective available issues. I use Drupal 8 and would like to do this with as little coding as possible since I think there are enough modules out there, I just cannot grasp the solution for the following case. I can add the list of available comic books by node reference. What I am having problem is to display the available issues for the selected comic book dynamically (so when the customer selects Batman from the comics list, the I would like to show the available issues related to the comic book).

Is there a UI-controlled method to do this with fields and/or entity reference? Should I use Views reference field or Entity reference view? (How?) Thanks any feedback on this :)


Is there a UI-controlled method to do this with fields and/or entity reference?

No, I don't think so.

Especially not when it's just a text field but also not when it's a more structured type of content. That kind of dynamic refresh/selection update requires custom code. You need to implement a module that alters the form with an ajax element that triggers a form rebuild that updates a second select based on what's in the other.

See How to dynamically populate select options? and How to fill select options based on previous select? for related questions. The first is for Drupal 7 but conceptually, it's still basically the same in Drupal 8.

Explaining everything in detail is too complex for the format of this site. You'll need to get started with tutorials on creating a module, form system, AJAX and so on, and then ask specific questions if you're stuck.

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.