开发者

Is it possible to create a UI for a has_many relationship with add / remove select box options?

开发者 https://www.devze.com 2023-04-03 13:31 出处:网络
The requirement is part of a support system. For each ticket the support system user needs to be able to select one or more companies and from those companies select one or more employees.

The requirement is part of a support system. For each ticket the support system user needs to be able to select one or more companies and from those companies select one or more employees.

The schema is so far setup as company has_many users and tickets are linked to users (regardless of company) by an intermediate table with simple ticket_id and user_id fields.

Previously a large multiselect was used but even with the company name added to the text and the collection ordered by company_name and forename the list quickly became extremely long and one false click and the selection would be reset.

I guess what I am looking for is a way to list companies, as the company is selected it will populate a list of users for that company with an add/remove to add or remove them from the list of users assigned开发者_C百科 to that ticket.

I am thinking :

Company dropdown -> [populates] -> user list -> [Add|Remove buttons] -> List of users saved in database.

Thanks in advance for any ideas.

Dave


Sure, although how you actually implement it could vary wildly.

If I were doing it my first try would use an autocompleter for the company name. Once I've selected the company, that company is added to a list of selected companies (not necessarily a select, although it might be represented by one internally, but the display would likely be something more attractive). Selected the company also enables, and sets a variable with the company ID for an employee autocompleter.

The display of the selected companies and employees would likely have a "remove" button (or just an "x" icon, like a tag) as well to make removal trivial.

Off the top of my head I can't think of a more intuitive way to implement this, but I'm sure there are other ideas.

0

精彩评论

暂无评论...
验证码 换一张
取 消