Skip to Content
Menu
This question has been flagged

I have a data xml file with a large number of zipcodes and city names that are correlated in the correct way.

I want to integrate a search into my contact form. When a user places his cursor in the field 'zipcode', a search box should appear and the user should be able to search for a zipcode of a city OR a city name itself (inside the same box). The reversed action should also be possible.

So when the user is typing names (in the field city or zipcode), the search dropdown should display the relevant data to his search. When the user places his cursor in the 'city' field. A search should be possible on zipcodes and city names. When the user selects the appropriate zipcode or city name (preferably displayed in the same line separated by a dash or so) the zipcode should be placed in the zipcode field and the city name in the city field.

How can I extend the default behavior of the search so that I can search through two columns and display the combined data in the search result box.

(PS: Yes I know, just split up the two searches... Not what I'm looking for though. PLIS NO HATE)

Avatar
Discard
Best Answer

From what I understood, perhaps one solution would be to create a separate table with zip codes and city with the correlation between the two.

You could then try redefining the fields city and zip as many2one fields to that table, instead of the ordinary text fields that they are defined as by default.

To show a combination of city and zip code, you can override def name_get() function. You can see examples of this in hr_holidays module, where the leave type (holiday_status_id) is combined with number of days remaining.

After selection, you can try triggering an on_change, which will fetch the corresponding zip/city value and populate the other field.

Hope this approach helps.

Avatar
Discard
Author

Thank you! I really like this approach. Will test it out soon and give feedback on the implementation.

Related Posts Replies Views Activity
0
Jan 23
707
0
Sep 21
3838
4
Apr 19
11686
0
Mar 15
3423
0
Mar 15
2771