Hi,
Hi, I have read this post https://toolset.com/forums/topic/how-to-import-states-and-countries-into-selects-for-fields/ and I would like to create an equal solution for the Italian regions, provinces and cities.
I have csv of thousands of municipalities in relation to the provinces.
How can I create conditional select between Region> Province> City?
I would like to use them within cred.
Thank you
The great thing about that other ticket is that another user took the time to manually create all the custom field options for each custom field. Then she exported the entire field set as a module. In your case, you don't have a module to work from so the process will be manual.
Here's the general idea. First you create a custom field that includes options for all your Regions. Each option for the custom field will include the name of the Region, with a slug-friendly value corresponding to that region. For example
Field: Regions
- Region A (region-a)
- Region B (region-b)
... and so on
Next, create separate custom fields for each Region, and include options that represent each Province in the Region. For example:
Field: Region A
- Province 1 (province-1)
- Province 2 (province-2)
Field: Region B
- Province 3 (province-3)
... and so on.
Then, create separate custom fields for each Province, and include options that represent each City in the Province. For example:
Field: Province 1 (province-1)
- City A (city-a)
- City B (city-b)
Field: Province 2 (province-2)
- City C (city-c)
- City D (city-d)
...and so on.
When you have all of those set up, you could export your Module without conditional display. Then you can begin adding your conditional display code. When the Regions field selection is "region-a", then you will hide all the other Province selection fields except Region A. When Province 2 is selected, you will hide all the City select fields except those belonging to Province 1. It's also possible to export the fields with just a few options predefined, then modify the XML file that is generated to include the new options, then import the updated field. This requires a good deal of XML knowledge, since you must transform your CSV document into a format that is compatible with XML.
Thanks for your help.
My dataset consists of:
20 Region
107 Provincie
8000 Cities
I have a csv with this data.
Do I have to manually enter in a Select all of this data manually? is there a way to optimize the process?
Do I have to create 20 + 107 conditions manually to hide the Select?
When do I have all this data on an html page, will it slow?
Do I have to manually enter in a Select all of this data manually? is there a way to optimize the process?
You have two options here. You can enter them all manually, or you can transform your CSV data into a format that can be imported using the Toolset Import / Export process. In order to do that, you must create a few connected Regions, Provinces, and Cities manually. Then export Types data using Toolset Export. You will find an XML file that includes the options you have already created. This will allow you to see the required format. Then you can convert your CSV file into this format using software of your choice, and insert the options into the exported XML document. Finally use Toolset Import to import your updated Types data with this updated XML document.
Do I have to create 20 + 107 conditions manually to hide the Select?
That's correct, you must add code for each conditional display group. You can see samples of the conditional code here:
https://toolset.com/documentation/user-guides/conditional-display-for-form-inputs/
When do I have all this data on an html page, will it slow?
This depends on quite a few factors, like CSS and HTML structure, as well as other page content, so it's difficult to say. In a test page, I was able to create 220 select fields with over 8000 total options divided amongst them, and apply some show and hide javascript to test this. The page loads fine on Chrome with a very basic design.
Thank you Christian, everything is clear to me. I ask you some information: You tell me:
you must create a few connected Regions, Provinces, and Cities manually. Then export Types data using Toolset Export. Can I please take a step-by-step example?
I do not understand well when you tell me: You will find an XML file that includes the options you have already created.
and finally tell me: Then you can convert your CSV file into this format using software of your choice. Can you give me some examples of software?
you must create a few connected Regions, Provinces, and Cities manually. Then export Types data using Toolset Export. Can I please take a step-by-step example?
- Create a custom select field that will hold all your regions. You can call this field "country" or something similar. Add options for two regions, I'll call them "region a" and "region b" but yours will be the real names of the regions.
- Next, create another custom select field that will hold provinces for "region a". You can call this field region-a-provinces or something similar. Include two province options that you know will be in region a, let's call them "province 1" and "province 2" for now, but yours will be the actual names of provinces.
- Next, create another custom select field that will hold cities for "province 1". You can call this field province-1-cities or something similar. Create two options for cities that will be in province 1, let's call them "city a" and "city b", but yours will be the names of actual cities.
- Next, create another custom select field that will hold provinces for region b. You can call this field region-b-provinces or something similar. Include two province options that you know will be in region b, let's call them "province-3" and "province-4".
- Finally, create one more custom select field that will hold cities for province 3, let's call them "city c" and "city d".
Now, go to Toolset > Export / Import and export your Types data.
I do not understand well when you tell me: You will find an XML file that includes the options you have already created.
When you export your Types data, the archive you download will include an XML file that includes the custom field information for the custom fields you created.
and finally tell me: Then you can convert your CSV file into this format using software of your choice. Can you give me some examples of software?
This part of the process is not something I can provide much assistance with, and requires substantial knowledge of XML document structures and formatting. You could use a code editor like Sublime Text, or you might find a wizard-driven tool useful, like hidden link
Thanks Christian, I imported the zip (hidden link ) with those created by a user but the fields are on Post Field but I would like to put them in User Field to create a registration CRED. How can I do?
Unfortunately there is not an easy way to transform Post Fields into User Fields. User and Post fields are stored in separate database tables, so it's not as easy as just changing a few settings. You would be required to do more manual XML modification to associate the field options with User Fields.
Thank you Chistian.
in which part of the xml file can I define User Field?
*****************
<?xml version="1.0" encoding="UTF-8"?>
<types>
<settings>
<add_resized_images_to_library>0</add_resized_images_to_library>
<register_translations_on_import>1</register_translations_on_import>
<images_remote>0</images_remote>
<images_remote_cache_time>36</images_remote_cache_time>
<help_box>by_types</help_box>
</settings>
<groups>
<group>
<ID>8044</ID>
<post_content></post_content>
<post_title>Countries, US States, & Canadian Province Lists</post_title>
<post_excerpt></post_excerpt>
<post_type>wp-types-group</post_type>
<post_status>publish</post_status>
<meta>
<_wp_types_group_filters_association>any</_wp_types_group_filters_association>
<_wp_types_group_fields>,countries,us-states-territories,canadian-provinces-territories,</_wp_types_group_fields>
<_wp_types_group_post_types>all</_wp_types_group_post_types>
<_wp_types_group_terms>all</_wp_types_group_terms>
<_wp_types_group_admin_styles></_wp_types_group_admin_styles>
<_wp_types_group_templates>all</_wp_types_group_templates>
<_wpcf_conditional_display>a:2:{s:8:"relation";s:3:"AND";s:6:"custom";s:0:"";}</_wpcf_conditional_display>
</meta>
<hash>91c743de940d33fbec7c906df100165e</hash>
<checksum>91c743de940d33fbec7c906df100165e</checksum>
<__types_id>countries-us-states-canadian-province-lists</__types_id>
<__types_title>Countries, US States, & Canadian Province Lists</__types_title>
</group>
</groups>
<fields>
<field>
<id>countries</id>
<slug>countries</slug>
<type>select</type>
<name>Countries</name>
<description></description>
<data>
<options>
My recommendation is to create a custom field manually with a couple of options. Then export the file, see how they are added to the XML document, and copy those structures for your new fields.