National Flags - Display user nationality in Discourse

Hi, thanks for the reply!

I chose to use the ISO Country Codes for a few reasons, the main one being laziness! :wink: the original files were already named with their country code. I realise it could potentially cause problems for users, but a quick Google search will get you your answer. (and using the codes avoids solves the translation issue ;))

I do hope to make some changes to the plugin in the near future and I’ll definitely look into displaying the countries in a more user-friendly manner.

1 Like

Since adding the plugin we seem to be getting a lot of warning messages in /logs, including:

TypeError: e.attrs.userCustomFields is null
Unable to get property ‘nationalflag_iso’ of undefined or null reference
TypeError: null is not an object (evaluating ‘e.attrs.userCustomFields.nationalflag_iso’)
Uncaught TypeError: Cannot read property ‘nationalflag_iso’ of null

Is anyone else seeing this?

If the cause of these log events is merely that a user hasn’t chosen a flag, then shouldn’t they just be Info messages, rather than Warnings?

1 Like

thanks for the feedback!
Yes, it looks like I’m not setting the default value for the custom field. This means all users who don’t have a national flag, don’t have a default value and its returning null.

I’ll have a look at it when I get a chance. It’s an unsightly warning message, but nevertheless just a warning message. :slight_smile:

This is fixed now. Just pushed the update to Github.
(I just added a conditional to the show-user-card connector, now you shouldn’t be getting any more warnings)


I was waiting for this fix before putting on my site. I just loaded the plugin on my site and I’m getting the errors. I’m also getting this weird bug when a user posts the dialogue box disappears and the post only shows if you refresh the page.

We saw something similar to your refresh issue after going to v1.8.0.beta5, it went away on it’s own.

That’s good to know. It wasn’t happening consistently, just intermittently for a few users…but enough for them to start complaining about it. Have your warning messages gone away? As soon as I loaded the plugin, I started getting them.

Can’t say yet, just updating my sandbox site now.

1 Like

The error messages stopped with the next update. (Thanks @Ebs )

1 Like

Ups, spoke too soon. I just updated the live site to latest, first user post after the update gives:

TypeError: null is not an object (evaluating 'e.attrs.userCustomFields.nationalflag_iso')
1 Like

Alright, that’s on the post decorator. Easy fix. I’ll do it tonight (and properly test it this time ;))


Thanks for your attention to this. In the few moments I had it up and running it was a big hit with my users. I run a political forum (don’t ever do that) and my users were quite excited to display the flags of the countries the post from, identify with, or just to pick flags based on countries that have policies that align with their political views. Great plugin and should be a part of core in my view (at least as an option).


:laughing: words to live by


I just upgradet to the latest version (720206f) but I still don’t get the National Flag option in my user preferences. :anguished: Might there be a conflict with another plugin? Or where should I start fixing this?

Have you enabled it in /admin/site_settings/category/plugins?filter=nationalflag?

1 Like

That would have been a nice solution, but yes, it’s enabled.

Edit: Whooops. Now the National Flag option has magically appeared. Maybe this was a caching thing…

@tophee, you said in the other thread that you’d disabled it
EDIT: glad its working now.

@JagWaugh I updated the plugin last night to hopefully fix the warning messages once and for all. It’s been running on my forum since then and (so far) no warnings.

Just updating the live site now…

Still getting:

Uncaught exception: TypeError: Cannot convert ‘e.attrs.userCustomFields’ to object

Uncaught TypeError: Cannot read property ‘nationalflag_iso’ of null

TypeError: e.attrs.userCustomFields is null

I take it that none of these are browser cache issues?

Since this topic is now the main place to discuss the plugin, I want to just mention a feature request I made elsewhere:

To put it more technically, can we let users choose a secondary National Flag right below the present flag setting? The scondary flag would be displayed next to the first one.