Fill a dropdown with cities depend on country select

I have a dropdown with countries and I need fill another dropdown with the cities of the country selected, but I really have no idea how to make the script, im very new in ERPNext.

This is my exact issue

Can you explain your issues more elaborate.

I just edited my post, thanks for ur attention <3

The resource you’re looking for and an explanation:

  1. You want the user to select from some list of options and then based on that, populate another list with those options. Country and Cities.
  2. An ISO list of countries ships with ERPNext, so you can get that list by assigning it to the options of a select field. IF you want that list to be filtered, or to not include or exclude some country specifically, use a filter query.
  3. You can repeat this pattern, but there isn’t a built-in dataset for cities, states or postal codes in ERPNext. I’d recommend the python package pycountry, which gets you states/provinces/subdivisions but no other address helpers. Maybe that’s enough.
  4. To get those subdivisions of countries in the UI, you need a callback that returns a list and then sets it to the the options in the docfield.

This callback should trigger on country.

 frappe.call({
   method: "dotted.path.to.python.method", // that returns a list of subdivisons when given a country argument
   args: {"country": frm.doc.country // where 'country' is the name of the docfield
 }).done((r) => {
    frm.set_df_property("city", "options", r.message);
 }).fail((f) => {
    console.log(f);
 });

What you’re asking for sounds simple but is actually hard to implement in an accurate way for all countries, which is why it has not been done yet in ERPNext. If you’re doing it for one country, it could be contributed as a regional module.

4 Likes

thanks you!, you help me a lot :heart:

Hola Sara, pudiste resolver el llenado automático?

PodrĂ­as detallar un poco cĂłmo lo lograste?

Gracias de antemano.

@Sara please kindly help me with your solution. i have similar case . state and local government

@tmatteson can you send serverside code

 method: "dotted.path.to.python.method"

@Kaushal_Khute I’ve never written it, I was just helping Sara with a strategy to solve this problem. I don’t know what she ended up doing.

@lubem did you get any solution

can you help me about issued ? i have same of problem’s ?

I’d be happy to help, but I can’t without more of an explanation of the specific problem you’re facing. It almost certainly should be in new thread.