On my site, I have a field, "Nationality," that allows users to select their home country. When I show this field in Views, thanks to the Countries module integration I am able to display the flag of the relevant country.

However, I would also like to be able to display the flags of each country within the countries select widget on the node/user edit page. For example, like the widget provided by the Language Switcher Dropdown module.

Thank you for your consideration!

Comments

Scyther’s picture

Project: Country Icons » Countries
Version: 7.x-2.0-beta1 » 7.x-2.x-dev

Country Icons only provides flags and a API for displaying them. So this should be a request to the Countries module to have them displayed in the select list for that field.

Alan D.’s picture

Project: Countries » Country Icons

Sorry to play ping-pong with the issue, but this feature would be useful on any country drop-down, particularly as core defines one too.

OK, some of the notes that I have gathered by looking at the existing solutions:

I think that the MSDropDown library should be independently installed in the sites/all/libraries.

Quick first stab at a possible implementation (JQuery side).

(function ($) {
Drupal.behaviors.country_flags = {
  attach: function (context, settings) {
    var settings = settings || Drupal.settings;

    if (settings.country_flags) {
      var flags = settings.country_flags.icons; // ? Support multiple sets?
      var selectors = settings.country_flags.selectors;
      if (flags && selectors) {
        $.each(selectors, function(index, selector) {
          $.each(flags, function(iso2, country_name) {
            $('select.' + selector + ' option[value="' + iso2 + '"]').attr('title', country_name);
          });
        });
        $('select.' + selector).msDropDown(settings.country_flags.settings[index]);
      }
    }
  }
};
})(jQuery);

The functionality could be inserted via an after_build to make it easy for this to be attached to any select element, either FAPI (like core) or Fields (like Countries module)

ie. Define a new after_build on the SELECT element.
If #country_icons FAPI property is set, append & setup the magic.

Thoughts? I am not sure how much time I personally have atm to develop this idea

Scyther’s picture

It looks good. But I don't think this should be included in this module. Maybe the best way is to have a own module for this?

philchen’s picture

Issue summary: View changes

Did this feature ever made though to the code?
Thanks!