Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements suggestions for the dropdown component #2746

Closed
davialexandre opened this issue Jul 30, 2015 · 3 comments
Closed

Improvements suggestions for the dropdown component #2746

davialexandre opened this issue Jul 30, 2015 · 3 comments

Comments

@davialexandre
Copy link
Contributor

I'm currently developing an application that have a lot of entities associations where both sides of the relationship have a large number of items. Because of this, I'm using remote dropdowns to show these entities. Specifically I'm using Select2.

I would love to remove the Select2 dependency and use the dropdown component for everything, but it still don't have some of the features that I need. I think these features would be nice improvements to the component:

Different templates/visualizations for the item
In some scenarios, it may be useful to have one template for when the item is displayed in the open dropdown and another for when it is selected and the dropdown is closed:

captura de tela 2015-07-29 as 20 48 35

captura de tela 2015-07-29 as 20 48 49

This can be partially achieved by customizing the dropdown templates, but since the label template don't have access to the received json data it is almost impossible to make it work for the closed dropdown.

Retrieve the selected item data
Sometimes, the loaded data has much more information than what is displayed by the dropdown. The data used by the last example is something like this:

captura de tela 2015-07-29 as 20 53 45

It would be very useful to be able to retrieve the json object for the selected item. I'm thinking of something like:

var selected_item = $('.dropdown').dropdown('selected item');
console.log(selected_item.cidade); // Would log "BOM JESUS"

I did some tests locally and I don't think it would be hard to implement this. If you agree that these are features worth implementing, I could make a PR

@jlukic
Copy link
Member

jlukic commented Sep 2, 2015

You can specify the text that should appear in label using data-text on the item. This is not compatible with dropdowns auto-generated from <select>

@projecttalk-issuebot
Copy link

Hi, thanks for posting your question.

Unfortunately, GitHub issues is specifically for bug reports and feature requests.

Since this post does not fit into that category, it has been moved to ProjectTalk boards, a special board specifically for usage questions.

Please check out our contributing guide to learn how to modify your post so that it might be appropriate for a bug tracker.

If you want to be notified about an answer, please go to http://www.projecttalk.io/boards/Semantic-Org%2FSemantic-UI/topics/21 and set your email preferences.

@kmd1970
Copy link

kmd1970 commented Aug 9, 2016

There is a workaround for custom dropdown templates.

Define your custom menu template:

var customMenu =  function(response, fields) {
    var values = response[fields.values] || {},
      html   = ''
    ;
    $.each(values, function(index, option) {
      html += '<div class="item" data-text="' + option[fields.label] + '" data-value="' + option[fields.value] + '"><div class="header">' + option[fields.name] + '</div><div class="meta"><span>' + option[fields.title] + '</span></div><div class="extra">' + option[fields.email] + '</div></div>';
    });
    return html;
  };

Then using the (undocumented) templates attribute override the default menu.

$('.ui .dropdown') .dropdown({
    templates : {
       menu : customMenu
    } 
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants