Single autocomplete textfield widget for address lookup (UX improvement)

Created on 30 November 2023, about 1 year ago
Updated 6 December 2023, about 1 year ago

Problem/Motivation

First, thank you for the effort on this module.

Currently, when using this module on international site, for each data entry one has to select a country first to be able to enter street address.

It would improve UX if you could provide a single autocomplete field widget for data entry.
at least for the APIs that support it.

Please take a look at (currently non functional for D10) Google Place Autocomplete module.

User interface changes

Single autocomplete textfield widget instead of default address widget with multiple address fields.
This would provide a major UX improvement.

Again, thanks for all the work on this project.

Feature request
Status

Closed: works as designed

Version

1.0

Component

User interface

Created by

🇭🇷Croatia odisei

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @odisei
  • Status changed to Closed: works as designed about 1 year ago
  • 🇫🇷France lazzyvn paris

    What a strange request, it seems you don't understand how to configure the address field, you can choose just one address, hide another.
    By the way google place is supported you can paste url api google place (in description) it will work.

  • 🇭🇷Croatia odisei

    Thanks for reply.
    Yes I know that you can hide address field elements, but you can't hide the country field, right?

    So, for a use case when you have multiple fields for address/location input (ie pickup, stops, dropoff location) for locations in different countries, for each location you have to select a country from a dropdown with almost 200 countries.

    All I'm saying, for such use case, single autocomplete field would improve ux.

    - single autocomplete textfield widget for lookup - data input,
    - data is saved in address field which is completely hidden on node edit form.

    Cheers

  • 🇭🇷Croatia odisei

    How much would it cost to implement this?

  • 🇫🇷France lazzyvn paris

    50$ i will update this feature in next version

  • 🇭🇷Croatia odisei

    Thanks lazzyn, let me know how to pay.

  • 🇭🇷Croatia odisei

    Lazzyvn, would it be possible to make this autocomplete field available as webform element?

    Currently there is no working implementation for webform compatible with Drupal 10.

    Similar (outdated) modules:
    https://www.drupal.org/project/places_api_webform_autocomplete
    https://www.drupal.org/project/webform_google_autocomplete
    https://www.drupal.org/project/webform_addressfield_extra
    https://www.drupal.org/project/webformautoaddress
    https://www.drupal.org/project/webform_location_addressfinder (only Australia nad New Zealand are supported)

  • 🇫🇷France lazzyvn paris

    - In the module description there is a donation link.
    - I don't think I have time to support web forms because web forms are not real entity fields.
    - I will add the option in formatter to hide the address field. in ProcessAutocomplete I will rewrite the address element Country, address 1, postal code, ... with hidden input. The autosuggest input feature will call ajax to populate the json from the api.

  • 🇭🇷Croatia odisei

    Hey, I just paid you.
    Let me know when it's ready!
    Thank you!

  • 🇭🇷Croatia odisei

    Hey lazzyvn, I see that you made the fork. I'm unable to download the module.
    I'm not familiar with git. Can you please upload the module tar.gz here so I can try it?
    Thanks!

  • 🇫🇷France lazzyvn paris

    Try dev version.
    Configuration in Widget: Check on Hide address field
    In field settings
    - Set default value
    - Set United State - USA or Canada - CA (because it has all the fields that other country without states choose)
    There is a problem with a country like Europeen, it still requires the state - remove by js but it still require so strange.

  • 🇫🇷France lazzyvn paris

    lazzyvn changed the visibility of the branch 3405331-single-autocomplete-textfield to hidden.

  • 🇭🇷Croatia odisei

    Yes, it's not working.

    Could you just make a widget for default textfield, and only include lookup fetaure?
    So the string value is saved in the default textfield instead of the address field.

  • 🇫🇷France lazzyvn paris

    Is there an error? show me the error.
    You can try with textfield widget

  • 🇭🇷Croatia odisei

    I tried on clean install with composer and got this error:

    The website encountered an unexpected error. Please try again later.
    
    Error: Class "Drupal\address\Element\Address" not found in include() (line 23 of modules/contrib/address_suggestion/src/Element/AddressSuggestion.php).
    
    Composer\Autoload\{closure}('/var/www/html/web/modules/contrib/address_suggestion/src/Element/AddressSuggestion.php') (Line: 427)
    Composer\Autoload\ClassLoader->loadClass('Drupal\address_suggestion\Element\AddressSuggestion')
    class_exists('Drupal\address_suggestion\Element\AddressSuggestion') (Line: 96)
    Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass('address_suggestion', Array, 'Drupal\Core\Render\Element\ElementInterface') (Line: 17)
    Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('address_suggestion', Array) (Line: 83)
    Drupal\Component\Plugin\PluginManagerBase->createInstance('address_suggestion', Array) (Line: 152)
    Drupal\Core\Render\ElementInfoManager->createInstance('address_suggestion') (Line: 121)
    Drupal\Core\Render\ElementInfoManager->buildInfo('claro') (Line: 77)
    Drupal\Core\Render\ElementInfoManager->getInfo('form') (Line: 816)
    Drupal\Core\Form\FormBuilder->prepareForm('system_modules', Array, Object) (Line: 284)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    After installing Address module the error is gone.

    Also, for Mapquest and Google Maps providers, I only get one suggestion in the dropdown below the field. Whatever the string.
    Tomtom gives multiple suggestions.

    I'll try to create a separate module as per your instructions on the module page, with places API and report back.
    Thanks

  • 🇭🇷Croatia odisei

    Here are issues I encountered while using latest stable Address Suggestion 1.0.14 + Address 8.x-1.12:

    1)
    Autocomplete Suggestions are limited in comparison to Google Maps Suggestions.
    On both textfield and address field you get only one suggestion...

    2)
    Street numbers are not saved to address field, only street name.

    3)
    Some country specific address fields are not saved despite the fact they are set to Optional (except locality) in address field settings.
    I get the errors for Japan (city or prefecture), Brasil (state), Canada (state), Australia (state) South Korea (Do Si)...

    Cheers

  • 🇭🇷Croatia odisei

    Forgot to attach address field settings.

  • 🇫🇷France lazzyvn paris

    Regarding the state, the control is complex and the value state is under the control of the Module Address. Address suggestion only gets value from api. State value from api is not always egale status value in Address module. I can't make mapping betwen state api vs state value of module Address. (that's why the address module requires selecting a country in the first step to create a state list).
    Address suggestion widget for Address field type is google for one country or don't have state (or you should disable state in field address settings)
    the best way in your case ( international address) have just use text field and map with geo field you dont need address field anymore

  • 🇭🇷Croatia odisei

    what about limited suggestions?

  • 🇫🇷France lazzyvn paris

    can you send me your google key i will check it. I just check free api

  • 🇭🇷Croatia odisei

    here AIzaSyDoYRE18905j9eW4o_vwhY6KqIy1pp6mJg

  • 🇭🇷Croatia odisei

    let me know when you get it so I can remove it

  • 🇫🇷France lazzyvn paris

    i got it

  • 🇫🇷France lazzyvn paris

    try dev version it fixed some bug.
    Google map api return only one address
    try with google place return 6 address

  • 🇭🇷Croatia odisei

    Yes, much better suggestions now with places API. Thanks.

    Regarding Address field integration, take look at Geocoder module, https://www.drupal.org/project/geocoder , it maps everything perfectly from the plain textifield.
    Unfortunately it does not provide autocomplete widget, it works only on node save, even with typos, values are saved correctly to address field.

    Maybe you can take look at it, and get the idea how to map values and address fields properly?

    Anyways thanks for help!

    Cheers

  • 🇫🇷France lazzyvn paris

    Oh, it supports geofield right from module creation, you can create Geo geofield in the same entity, you will see this field in configuration widget, select this field. you can hide this geofield by using css or field group

Production build 0.71.5 2024