Changing between drop-down and autocomplete for locations

From OSClass

From version 2.2, we offer the possibility to change between a drop-down and autocomplete inputs for locations (When users input their country, region, city,...)


Contents

Drop-down input

Pros

Easier for users, they just need to select their location from a given list.

Cons

Limited or incomplete geo data, maybe not every country, region or city is in the list, so users will not be able to select their current location.


How to enable it

To enable the drop-down menu, you need to modify two front-end files of your current theme, item-edit.php and item-post.php, also an admin file (oc-admin/themes/modern/items/frm.php).


First, change the JS call from (this change is common to all three files):

<?php ItemForm::location_javascript_new(); ?>

to

<?php ItemForm::location_javascript(); ?>


item-edit.php, from :

<?php ItemForm::region_text() ; ?>
...
<?php ItemForm::city_text() ; ?>

to:

<?php ItemForm::region_select() ; ?>
...
<?php ItemForm::city_select() ; ?>


item-post.php, from :

<?php ItemForm::region_text(osc_user()) ; ?>
...
<?php ItemForm::city_text(osc_user()) ; ?>

to:

<?php ItemForm::region_select(osc_get_regions(osc_user_country_code()), osc_user()) ; ?>
...
<?php ItemForm::city_select(osc_get_cities(osc_user_region_id()), osc_user()) ; ?>


frm.php, from :

<?php ItemForm::country_text($item) ; ?>
...
<?php ItemForm::region_text($item) ; ?>
...
<?php ItemForm::city_text($item) ; ?>

to:

<?php ItemForm::country_select( ) ; ?>
...
<?php ItemForm::region_select( ) ; ?>
...
<?php ItemForm::city_select( ) ; ?>

Auto-complete input

Pros

More freedom is given to users, they will be able to select a location from the current database/list if they start typing it, but they will also be able to introduce new data.

Cons

They are allowed to enter anything as a location. You should trust your users.


How to enable it

To enable the auto-complete input, you need to modify two front-end files of your current theme, item-edit.php and item-post.php, also an admin file (oc-admin/themes/modern/items/frm.php).


First, change the JS call from (this change is common to all three files):

<?php ItemForm::location_javascript(); ?>

to

<?php ItemForm::location_javascript_new(); ?>


item-edit.php, from :

<?php ItemForm::region_select() ; ?>
...
<?php ItemForm::city_select() ; ?>

to:

<?php ItemForm::region_text() ; ?>
...
<?php ItemForm::city_text() ; ?>


item-post.php, from :

<?php ItemForm::region_select(osc_get_regions(osc_user_country_code()), osc_user()) ; ?>
...
<?php ItemForm::city_select(osc_get_cities(osc_user_region_id()), osc_user()) ; ?>

to:

<?php ItemForm::region_text(osc_user()) ; ?>
...
<?php ItemForm::city_text(osc_user()) ; ?>


frm.php, from :

<?php ItemForm::country_select($countries, $item) ; ?>
...
<?php ItemForm::region_select($regions, $item) ; ?>
...
<?php ItemForm::city_select($cities, $item) ; ?>

to:

<?php ItemForm::country_text($item) ; ?>
...
<?php ItemForm::region_text($item) ; ?>
...
<?php ItemForm::city_text($item) ; ?>


Read the following article, if you want to learn more about How to configure locations.