0

I have a model hierarchy that looks something like this:

Office
   |
   +-- Person

That is, every Office has multiple Person.

I want to allow a user to select a Person using an autocomplete text input field (using jQuery UI Autocomplete). In this text input field, I allow the user to type text, which is matched server-side against the last name, first name, and login of the Person to find matches to suggest to the user while he/she is typing.

Recently I ran into the problem where sometimes users only know limited info, like the Office name and the first name of the Person. They can't simply type "John" into the autocomplete field, as it will match hundreds of "John"s, and they have to scroll through all of these, searching for the one in the right Office.

My question is, what's the best way to allow users to search for a Person using criteria from both Office and Person?

I'd prefer to keep the UI as sleek and minimal as possible, so I'm trying to stay away from multiple fields, overlayed lookup popups, and things of that nature.

3 Answers 3

2

Check out http://jquery.bassistance.de/autocomplete/demo/ then click

"Click here for an autocomplete inside a thickbox window."

For a demo on their plugin. This implements compound autocomplete, which you could use to maybe use Person as the primary record and the office as the smaller information on the bottom. It may take some tweaking to get it to match the way you want, such that a space would start a new expression.

Example:

currently john west does not match

John Smith
Office: West Park

but delimiting by space for a new expression would match the name and office simultaneously.

You can, however, currently match that entry by typing either John or west

Sign up to request clarification or add additional context in comments.

4 Comments

I guess the problem with this method is figuring out how to associate the office name with a given user without denormalizing my database schema, but it's a good suggestion nonetheless. I just may use this one.
Well does the person have an office id? Depending on your platform, something to the extent of loop -> User, FindOffice(User.office_id) -> /loop
Yes, but this is an autocomplete, so performance is a big issue. Looping through each user and looking up the office for it would be too slow. I'd likely have to join the tables and create a model from the results, and search that instead.
What server side coding are you doing?
1

I'd first give them an optional dropdown to select Office, and then populate the auto complete with each Person from the Office. You could then include functionality that would allow them to select a Person first instead, and that would also populate the Office.

2 Comments

This was the first method I thought about, but I didn't like the idea of adding the extra field on the form, because like I said, I'm trying to keep everything as minimal as possible.
Understood, and besides I'm really liking Kyle's suggestion.
0

Maybe give them a way to tag the Office portion of the search string? Like @office so a user could type john@scranton or john smith @scranton.

1 Comment

This method is very similar to @KyleMacey's, but a little less flexible if I were to ever want to add an additional search field (I think john@scranton@pennsylvania would be confusing for users.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.