Filter Entity reference based on attribute
The best way I found offering a very high amount of flexibility is to combine the two following components:


The Dynamic Dependent Fields (DDF) module takes in charge the relation between the other fields composing your form and your Entity Reference field.

Concretely, it will add a new mode for the entity selection, "Views: Filter by an entity reference view with dynamic argument", which allows you to dynamically pass the value of one or several other fields of your edit form as contextual filters to a view.

The magic here is that the values proposed by your Entity Reference is dynamically updated upon modification of the controller fields content (JavaScript).

The only limitations I encountered with this module is that it does not support autocomplete fields as the controlee Entity Reference fields, drop-down lists must be used instead. Moreover, DDF does not take into account programmatically set default values for the controller fields, however I submitted a patch solving this.
A patch for Entity Reference (currently in RTBC status) adds the possibility to use tokens now as contextual filter for the views and complement very well the above mentioned DDF module.

For instance, this patch allows very easily to exclude the current entity from the Entity Reference available choices.


Associating the two modules let your Entity Reference fields available values to be generated by a View taking into account both tokens and other fields values. Hard to get more flexibility !