Get select options for an entityreference field using another field as a contextual filter? I have a Course Offerings vocabulary where each taxonomy term is an educational course.
Users have a multivalued My Courses Entity Reference field referring to the terms of the courses they're enrolled in.
I have a custom content type (Entityform) with two more Entity Reference fields: a Course field and a Student field. The user must first select a course (a Course Offerings taxonomy term), and then select a student (a user).


Here's the kicker: I need to filter the Student select list options based on what the user selected in the Course field.

The Course field select options are generated by a view that returns the current user's My Courses field courses. After the user selects one of their courses, the Student field select options should be generated by a view that uses the course they chose as a contextual filter to return a list of only the users enrolled in that course.

I know how to build the view once I have the contextual filters, but I'm stumped as to how to pass the Course term to the view as a contextual filter. Is this possible?

EDIT FOR CLARIFICATION:


Both the Course and Student fields are Entity Reference fields.
Both use select-list widgets whose options are populated with views Entity Reference displays.
The Course field comes before the Student field on the eform. The intention is that the person filling out the form will first choose the course. Then they'll choose the student from a list of students enrolled in the course they just selected.
I've kept an eye out for a module that does this since the original post, but never came up with anything. I've been using a sort of "one off" solution to do this on a case-by-case basis instead:


In a custom module, implement hook_form_FORM_ID_alter() for the
form with your dynamic fields.
Add #ajax attributes to the first element to trigger and handle
changes to it with AJAX. This will specify the AJAX callback handler
and the HTML ID of the element to be replaced with the AJAX response.
In the ajax callback for that element, use the AJAX-submitted value
to dynamically get the appropriate values for the second value. For
me, this is usually a query of some sort with the submitted value as
a filter.
Update the second field's form element #options attribute with the
dynamic values and return the element.