1

When in Lightning why doesn't the standard text input field provide autocomplete like it does when in Classic?

i.e. I have a text field in a custom object, I go to create a new record and the browser does not remember any of the previous values I entered into that text box. But it does when using Classic.

Note: I'm using Google Chrome.

2

Autocomplete only works when a form is submitted. Because Lightning does not use a form tag, and it never submits forms to the server (it's all AJAX-y REST API calls), browsers are convinced that there's nothing to save in the autocomplete cache.

If you really want to, though, you could choose to put a form in your application or component, submit it, and it will cause the browser to remember the values.

A simple application demonstrates this:

<aura:application extends="force:slds">
    <form aura:id="form" target="iframe" action="#" onkeypress="{!c.blockEnter}">
        <lightning:input type="text" label="Name" name="name" />
        <lightning:button label="Add to Autocomplete" iconName="utility:save" onclick="{!c.saveAutoComplete}" />
    </form>
    <iframe id="iframe" name="iframe" class="slds-hidden" />
</aura:application>

({
    blockEnter: function(component, event, helper) {
        if(event.which === 13) {
            event.preventDefault();
        }
    },
    saveAutoComplete: function(component, event, helper) {
        component.find("form").getElement().submit();
    }
})

When you enter a value, then click the button, your browser will remember the stored value. Please feel free to customize this behavior as you like.

  • Am confused. Its form Autofill or autocomplete? – Pranay Jaiswal Mar 22 '18 at 10:24
  • 2
    @PranayJaiswal Autofill is a technology that populates your name, phone, email, etc into forms. Autocomplete is a technology that remembers values stored in a particular form element for later recall. This answer addresses autocomplete. Autofill should work regardless as long as the browser detects that it's a form you want to put your personal information in to. It seems to trigger in Chrome if there is at least one email, phone, or address field, possibly other scenarios as well. I don't know the exact criteria. – sfdcfox Mar 22 '18 at 10:39
  • This is a really frustrating behaviour of Lightning, – Robs Mar 22 '18 at 15:06
  • @Robs I concur. It'd be a lot nicer if autocomplete were more functional. That's why I came up with the example code; you can implement this in any custom component to give the user the ability to use it again. Unfortunately, there's still no practical way to allow/enable/force this feature in the general UI, but at least in your own components, you can have some control over it. – sfdcfox Mar 22 '18 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.