I have a large data source file with postal codes and cities throughout the world. I would like to have the option of doing an “auto complete” similar to the one frappe/erpnext uses when filling out a form such as this:
The data is about 30MB if raw text which I uploaded as a doc type. I want to use this data to be able to perform auto complete or lookups when filling out addresses for shipments. For example, if I know the city name, but not the postal code, then begin typing the city name and have it start returning possible postal codes as frappe searches the data storage. Similarly if I have the postal code, then start typing it in and narrowing down the search results, and when the correct one is fully entered have the “city” field populate with the corresponding city name.
What would be the proper way to do this in a fast lookup method? Right now when I tried doing a drop down it takes forever to just load the doc type for the custom doc type screen because it is trying to load the entire data source at once and its very slow. Any suggestions? How can it be done to be as smooth as the frappe/erpnext one even with thousands of records?
The autocomplete is built into the ‘link’ field type. It sounds like you’ve already done the first half of what I’m about to say, but I’m not sure how your data is structured.
Here’s what I would do:
Create a custom doctype. We’ll just call it ‘Postal’ for this example.
have fields for each type of data. such as:
‘City’
‘Postal Code’
Make the naming type ‘field:postal_code’
Create two custom fields in the document of your choice.
Label:“Postal Code”
Type: Link
Options: Postal
Label:“City”
Type: Data
Add a custom script to the doctype you added the custom field to:
cur_frm.add_fetch(“postal_code”, “city”, “city”);
The link field ‘Postal Code’ should autocomplete. You can only type in the postal code field, but you can start typing a city name and it will still search. When you select one, the City will be put in the ‘city’ field.
Ok the issue about the auto complete is resolved, but the issue now is the speed. The database is extremely slow due to the large dataset of over 100k records. Any suggestions on how to improve this?
If you start entering by country (like with navigation tools), than the search could be narrowed down much faster.
I would really like to see this feature implemented into erpnext. this would make entering new customers much more fun and data could be more reliable (typos, no wrong numbers in postal code) and users can verify address data easier.
Plenty of advantages!
should we file a feature request in github?