2

is it possible to switch off autocompletion in the adressfields? I can see there is

<template v-if="useAutocomplete">

in the template. But where can I set it to "false"?

Albrecht
  • 135
  • 1
  • 8

3 Answers3

3

I'm also interested in this. I'm sure the intention is to allow developers to turn off the auto-complete feature but I wasn't able to get this to work. As a workaround, you could override the template by overriding the address-fields component:

    <div hidden id="snipcart" data-api-key="API_KEY">
        <address-fields>
            <div class="root">
                <div class="snipcart-form__row">
                    <div class="snipcart-form__field snipcart-form__cell--large">
                        <snipcart-label class="snipcart__font--tiny" for="address1">
                            {{ $localize('address_form.address1') }}
                        </snipcart-label>
                        <snipcart-input name="address1"></snipcart-input>
                        <snipcart-error-message name="address1"></snipcart-error-message>
                    </div>

                    <div class="snipcart-form__field snipcart-form__cell--tidy">
                        <snipcart-label class="snipcart__font--tiny" for="address2">
                            {{ $localize('address_form.address2') }}
                        </snipcart-label>
                        <snipcart-input name="address2"></snipcart-input>
                        <snipcart-error-message name="address2"></snipcart-error-message>
                    </div>
                </div>

                <div class="snipcart-form__field">
                    <snipcart-label class="snipcart__font--tiny" for="city">{{ $localize('address_form.city') }}
                    </snipcart-label>
                    <snipcart-input name="city"></snipcart-input>
                    <snipcart-error-message name="city"></snipcart-error-message>
                </div>

                <div class="snipcart-form__field">
                    <snipcart-label class="snipcart__font--tiny" for="country">{{ $localize('address_form.country') }}
                    </snipcart-label>
                    <snipcart-typeahead type="dropdown" name="country" autocomplete="country"></snipcart-typeahead>
                </div>

                <div class="snipcart-form__row">
                    <div class="snipcart-form__field snipcart-form__cell--large">
                        <snipcart-label class="snipcart__font--tiny" for="province">
                            {{ $localize('address_form.province') }}
                        </snipcart-label>
                        <snipcart-typeahead type="dropdown" name="province" autocomplete="province state">
                        </snipcart-typeahead>
                    </div>

                    <div class="snipcart-form__field snipcart-form__cell--tidy">
                        <snipcart-label class="snipcart__font--tiny" for="postalCode">
                            {{ $localize('address_form.postalCode') }}
                        </snipcart-label>
                        <snipcart-input name="postalCode"></snipcart-input>
                        <snipcart-error-message name="postalCode"></snipcart-error-message>
                    </div>
                </div>
            </div>
        </address-fields>
    </div>

See: https://docs.snipcart.com/v3/setup/customization

I'm hoping someone chimes in with a better answer.

  • I heard back from a snipcard rep. The above is the way to do it (though they are working on a better one). – Iljya Kalai Nov 10 '20 at 16:36
  • Hi @Iljya Kalai - may I know how you were trying to set the `useAutocomplete` property as `false`? I know you said it did not work, but I'd also like to try it on my setup. Thanks! – Talha Nov 25 '20 at 00:18
  • For what it's worth i can see it's a feature flag in `Snipcart.store.getState().session.featureFlags` however not sure where to even set it. – Talha Nov 25 '20 at 00:39
  • sorry, I can't remember anymore... anyways, the Snipcart folks told me the way I show above is the way to go for now, surprising I know – Iljya Kalai Nov 26 '20 at 16:48
  • No worries, thanks! Yes, it is surprising, haha. There's also some gaps in the JS API documentation regarding this so I'm hoping that this is something that will come soon. To move forward at least this solution is good. – Talha Nov 26 '20 at 18:58
  • It seems, at least for me, that the province part is required for this customization to work. If you leave it out, because it's irrelevant or not applicable in some countries, the "Continue to payment" button won't work. There even is no error in the console that could explain the not working. This doesn't make any sense to me, to force using of province field, so I'm thinking maybe I'm getting it wrong? Anyone else with the same issue? –  Feb 26 '21 at 10:53
  • That's seems like an entirely different question, WebShaped.Biz – Iljya Kalai Feb 26 '21 at 14:38
  • You're right @IljyaKalai, I wasn't thinking, my bad. –  Feb 27 '21 at 16:45
  • @WebShaped.Biz did you figure out the issue with the "Continue to payment" button with the province field? – scar Apr 06 '21 at 14:45
  • @scar This field is required and that won't be changed, according to support guys. however, just today I've received a support message saying this: Hi there, One way I could see this achieved is by setting the Province field programmatically using our JavaScript API https://docs.snipcart.com/v3/sdk/api#update every time a cart is created https://docs.snipcart.com/v3/sdk/events#cartcreated and hiding the province field using CSS. Let me know if that helps, Cheers! –  Apr 07 '21 at 15:06
  • @scar Update: Version 3.1.0 was released yesterday (7. April) and in release notes there is a line saying that Province is no longer required :-) I've tested it and it really is not required anymore. Yay! –  Apr 08 '21 at 07:53
  • @WebShaped.Biz yaaay! That's great timing. thank you! – scar Apr 08 '21 at 16:26
0

The accepted still appears to be the officially documented way to do this (April 2021, using Snipcart v3.0.31), but I’d also prefer not to overwrite templates for functionality already built into the checkout.

The autocomplete input also gives you a checkbox where you can opt-out and manually enter your address, which restores the default address templates.

The default Snipcart checkout “I can’t find my address” checkbox

Another option is to always check that box for the user, before they do anything else in the cart:

let disableAddressSearch = function () {
  let fauxEvent = new MouseEvent('click', {
      view: window,
      bubbles: true,
      cancelable: true
  })

  let input = document.querySelector('input[name=addressNotFound]')

  if (!input) {
    return null
  }

  let result = input.dispatchEvent(fauxEvent)

  if (!result) {
    // You probably don’t want this in production
    console.warn('Couldn’t disable autocomplete checkbox')
  }
}

You can try this out in the console on the Checkout page. Now, we want to do this each time the customer gets to the checkout.

// https://docs.snipcart.com/v3/sdk/events#themeroutechanged
Snipcart.events.on('theme.routechanged', function (routesChange) {
    if (routesChange.to === '/checkout') {
        console.log('cart opened');

        // A timeout that should be long enough for the checkout
        // to be rendered
        window.setTimeout(disableAddressSearch, 100)
    }
})

The timeout isn’t completely reliable, but it seemed like an acceptable tradeoff to me versus watching for the element to appear, ex. using MutationObserver.

kennethormandy
  • 2,080
  • 14
  • 16
0

This feature can be disabled by our team (I'm working at Snipcart) if you contact support. We have plans to make it configurable from the dashboard though.

It's possible to do it by overriding our components too, but a bit more complex.

Charles Ouellet
  • 6,338
  • 3
  • 41
  • 57