The easiest way would probably be to create a table in your database with the countries and use this as a prevalue source in Contour. I created a wrapper FieldType for the uComponents Country Picker once but then found out that it doesn't include all countries, so I started using a static DB table instead.
This blog post gives a pretty good example on how to setup a prevalue source. It's either that or manually enter each country in... and that's not really an option.
Do you use Visual Studio? I can paste the code I used to create the Country Picker fieldtype below, it's pretty simple - just need to add a reference to the Contour DLL. Actually it doesn't use uComponents but uses the same methods to populate the dropdown. Again the problem is that it is missing certain countries, but if you're OK with that it should work. Otherwise the Prevalue Source is probably the best way :)
[Umbraco.Forms.Core.Attributes.Setting("Choose Text", prevalues = "", description = "Enter the text to show as the default option in the dropdown (Default=Choose Country...)", control = "Umbraco.Forms.Core.FieldSetting.TextField")] public string ChooseText { get; set; }
public List<Object> Value; public DropDownList ddlCountries;
public CountryPicker() { Id = new Guid("3B41BB75-699D-42D4-8FD0-5E189E6E9588"); Name = "Country Picker"; Description = "A drop down list filled with countries"; Icon = "textfield.png"; DataType = FieldDataType.String;
ddlCountries = new DropDownList(); Value = new List<object>();
Thanks, problem was caused by not inheriting from Fieldtype. My code compiles now.
Have been been thinking about it. Maybe for Contour it's more natural to use a Prevalue Source. I read the blog post on Prevalue Sources for Contour that Douglas was suggesting and it doesn't seem like a hard thing to implement. The only thing I'm wondering about, is how to create this Country table.
I can't imagine someone typing in all those countries manualy :)
Is there somewhere a Countries table, or a script that can be downloaded?
Mission accomplished. After taking some hurdles (importing the countries data from a flat file to my Countries table, and finding the correct syntax for my connectionstring) I was able to create the Countries prevalue source.
country picker in Contour
Hi,
Is there a way to have a country picker in a Contour form?
Thanks for your help,
Anthony
Hi Anthony,
The easiest way would probably be to create a table in your database with the countries and use this as a prevalue source in Contour. I created a wrapper FieldType for the uComponents Country Picker once but then found out that it doesn't include all countries, so I started using a static DB table instead.
-Tom
This blog post gives a pretty good example on how to setup a prevalue source. It's either that or manually enter each country in... and that's not really an option.
@Tom, thanks for the advice, I'm using the uComponents Country Picker already, but I don't know how to create the wrapper FieldType for Contour.
@Douglas, thanks Douglas for the information, I was looking for some more information on how to setup a prevalue source
greetings,
Anthony
Do you use Visual Studio? I can paste the code I used to create the Country Picker fieldtype below, it's pretty simple - just need to add a reference to the Contour DLL. Actually it doesn't use uComponents but uses the same methods to populate the dropdown. Again the problem is that it is missing certain countries, but if you're OK with that it should work. Otherwise the Prevalue Source is probably the best way :)
-Tom
Hi Tom,
Thanks a lot for the code. So I just add this as a class in a Visual Studio project and compile it?
greetings,
Anthony
Yep, add a class (CountryPicker) in VS, add a reference to Umbraco.Forms.Core.dll, paste the code, compile, then drop the DLL in your /bin/ folder.
ok, clear, you also mentioned that I should add a reference to the Contour.dll or is that the same as Umbraco.Forms.Core.dll
Yes, that's the one
ok, I'll let you know if it worked out.
thanks
Hi Tom,
I created my class, but still have some squiglies:
the override methods aren't recognized ("no suitable method found to override")
This are my using statements:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using Umbraco.Forms.Core;
using Umbraco.Forms.Core.FieldSetting.Pickers;
using System.Globalization;
Is it posible to give me the Using Statements you are using in your project?
Thanks,
Anthony
Sure, here you go, sorry about that.
Also your class needs to inherit from FieldType, ie:
HiTom,
Thanks, problem was caused by not inheriting from Fieldtype. My code compiles now.
Have been been thinking about it. Maybe for Contour it's more natural to use a Prevalue Source. I read the blog post on Prevalue Sources for Contour that Douglas was suggesting and it doesn't seem like a hard thing to implement. The only thing I'm wondering about, is how to create this Country table.
I can't imagine someone typing in all those countries manualy :)
Is there somewhere a Countries table, or a script that can be downloaded?
If not, I'll give the wrapper class a go.
greetings,
Anthony
I agree, I don't use that fieldtype anymore as I said :)
You can find lists on the web in different formats to import into your DB, here's a good start: http://www.iso.org/iso/iso_3166_code_lists
Ok, thanks a lot
Hi guys,
Mission accomplished. After taking some hurdles (importing the countries data from a flat file to my Countries table, and finding the correct syntax for my connectionstring) I was able to create the Countries prevalue source.
Thanks to Douglas and Tom for their help!
greetings,
Anthony
is working on a reply...