Is it possible to change the result of the view depending on the value being selected on the form, node creation form without saving it first?

Last time, my problem was filtering the views depending on the field value of current node and I found the answer using

Filter View by Entity Reference Value From Current Node -

$node=menu_get_object(); return $node->field_venue_for_catering['und'][0]['target_id'];

But when I tried this on an entity reference view, it doesn't show any result unless I save the form.

The case from the link given above is almost the same for this post, the difference is filtering the view dynamically without saving the form first.

Is there anyone that will be able to help?

Thank you very much!!!

1 Answer 1


Here's my solution:

I used Entity Reference Prepopulate for my "venue" for my case (linked from my question), so whenever I choose a venue it will pass a parameter to the url.

Then I used Views Contextual Filter Query to get the value of the parameter from the URL and automatically filter the view without saving the form.

BTW, Entity Reference Prepopulate doesn't work on edit form, so you need to create a node_load function on your custom module. Check this for code reference

Then I created a code for edit link that has the param of venue and it's target id.

    $nid = arg(1);

    $l = l( t('EDIT'), 'node/'.$nid.'/edit',   array('query' => array('field_product_venue' => $node->field_product_venue['und'][0]['target_id'] )  ));
    echo $l; 


I hope this will of help to somebody!


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.