By 'trim' I mean that I want to restrict the usernames returned according to some criterion. For example, if I enter 'S' into my user reference field, I want the drop-down list to contain all usernames begining with 'S' and where, for example, the users favourite color equals 'Red'. 'Favourite color' would be a field added on to the user entity.
My first idea is to use hook_query_alter to add a condition clause to the relevant query in user_reference module, but I'm not sure if this is possible. Has anyone done something like this before?
Thanks