0

I have two content types that share a taxonomy (Size).

On content type A, I have an "entity reference" to content type B in the form of a checkbox widget.

What I want: On the node creation form, when I change the size (without saving), the entity reference filter gets updated appropriately.

What I currently have: The entity reference filter only changes when I save the node.

How I got there:

I'm using an Entity Selection views filter by entity reference view

In my entity reference view, the only thing I could come up with is to set a contextual filter of "content has taxonomy term ID"

Then use "provide default value" -> "taxonomy term ID from URL" and "load default filter from node page"

So, If I create a new node of type "A" and set "Size" to "Size X" and SAVE the node, the entity reference gets filtered properly.

What I want to happen is that on the node creation form, when I change the size it dynamically filters the entity reference without having to save the node.

There is no ajax option on an entityreference views display, and I"m not seeing any other modules that seem to solve this.

Can anyone point me in the right direction here?

  • I have a working solution using this: drupal.org/project/reference_option_limit The main difference is that I had to use a 3rd content type instead of a shared taxonomy. This post was especially helpful in getting to a working solution with this module. drupal.org/node/1596162 – CCMonkey Dec 5 '13 at 20:10
  • Oh wow, cool. Example 2 on that module's description makes it sound like it should work with taxonomy, not just a third node type. Could you not get it to work as it describes? – 75th Trombone Dec 5 '13 at 20:12
  • @75thTrombone Exactly. Even though they both had the same term reference field, the option never "came on" for me to check the box. Maybe something related to my configuration in particular, although I don't see any major reason using a content type for the size is any more or less valid than the taxonomy, so in my case it seems fine. – CCMonkey Dec 5 '13 at 20:17
0

I'm not sure this question has a good, Drupalish answer. I've got a crazy idea, though, that you might try.

Instead of letting your users go straight to node/add/typeA, send them first to a custom page where they choose their size. That link will then send them to the node add screen with a TID tacked onto the end, like /node/add/typeA/34.

On the node creation page, your custom module will automatically select the right Size term based on the URL path, and disable the widget so the user can't change it.

In your Entity Reference view, when you provide a default value to your contextual filter, instead of "Taxonomy term ID from URL", simply choose "Raw value from URL" and set the Path component to 4. With any luck, the Entity Reference view will get the TID from your modified URL and show the right list.

When they try to edit that node after creation it gets a bit tricky. You could just forcibly redirect the path to node/[nid]/edit/34 and do the same thing, but now you've made it so the user can never change the category after they select it the first time, which is bad. Maybe you can hijack node/[nid]/edit and send them to your custom page again? I've never seen that done before.

This whole idea kind of craps up the usability of the site, but it's the best idea I can think of, short of writing your own custom AJAX stuff to provide your argument to the ER view manually, rebuild the form, etc.

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.