Hi everyone,
I'm working on Adaptive form in which I've dropdown for Country Names. Now, I want to populate the list of full country name, but the values should be their 3-letter code. Something like below.
<option value="AZE">Azerbaijan</option>
<option value="AUS">Australia</option>
Adding 105 items manually to the dropdown field is lengthy. So, I tried Function Output feature of AF but I can only populate country names without their codes like below:
<option value="United States">United States</option>
<option value="Norway">Norway</option>
Got above output by using this:
const countryList = [
"Afghanistan",
"Albania",
"Algeria",
"American Samoa"];
But can't leverage this:
const countryListAlpha3 = {
"AFG": "Afghanistan",
"ALB": "Albania",
"DZA": "Algeria"};
Using country list from this (line 528 have 3-letter codes) GitHub link. I'm not sure how to add value to dropdown items.
Can someone please help me to accomplish this?
Regards,
Sesmic
Solved! Go to Solution.
Views
Replies
Total Likes
here is a link to live example of the capability
you can use publicly available API to get the list of countries and populate the drop-down list
I have written an article on this
let me know if you have trouble getting this to work on your system
here is a link to live example of the capability
Hi @gbedekar
Thanks for the reply!
I read your article while learning AF and implemented it. Felt awesome
But, in current use case there's no dependent DropDownList just country names. I simply want list of countries with their codes as value because the submitted value is important after submission.
you can follow the article to implement a form data model service to fetch the countries list from any of the publicly available api
https://www.universal-tutorial.com/rest-apis/free-rest-api-for-country-state-city
This API returns the countries and code associated with it
lets have a call
send a private message
or you can use the item load property to load the values in tour drop down list as shown in this article
Appreciate your effort.
For item load property, is there any way to save values fast or manually entering them is last resort?
Will look into API idea you shared, but afraid client will like it or not.
Anyways thanks @gbedekar . Will message you if needed.
there are two options
one is to find REST API that returns the data in the format your want - Drawback you may have to pay for it or if its free there is no guarantee that it will be up 24/7
The other option is to write your custom servlet that will return the json of the countries in the format you want
or you can use item load path property.
In any case you will have to go through the effort of creating the countries list
Will it not be possible to accomplish this with Function Output or Rule editor? My JS is not good, so couldn't get the expected result.
Views
Likes
Replies