question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hosted Fields Instance focus is not working properly on iOS Safari

See original GitHub issue

General information

  • SDK version: 3.39.0
  • Environment: Sandbox and Production
  • Browser and OS: Mozilla/5.0 (iPhone; CPU iPhone OS 12_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1 on iOS - iPhone 8 plus

Issue description

Hi, we are trying to implement an automatic focus change to next field for Credit Card fields. What we are trying to accomplish here is that when the user fills out the credit card number filed and it is determined as valid it immediately changes the focus field to next one (ex. date, then from date to CVV). We have successfully accomplished that on desktop browsers by using these lines of code:

Calling a function makeFieldValid() on validity change:

hostedFieldsInstance.on('validityChange', function(event) {
    var field = event.fields[event.emittedBy];

    if (!field.isValid && !field.isPotentiallyValid) {
        // Case when there is an error
        makeFieldInvalid(event.emittedBy);
    } else if (!field.isValid && field.isPotentiallyValid) {
        // Case when it's neutral
        makeFieldNeutral(event.emittedBy);
    } else {
        // Case when it's valid
        makeFieldValid(event.emittedBy);
    }
});

makeFieldValid() function sets focus to next field if determined as valid:

function makeFieldValid(field) {
    var $fieldContainer = $(hostedFieldsInstance.getState().fields[field].container);

    $fieldContainer.next().html(getFieldLabel(field));
    $fieldContainer.next().css('color', 'green');
    $fieldContainer.css('border', '1px solid green');

    if (field == 'number') {
            hostedFieldsInstance.focus('expirationDate');
    } else if (field == 'expirationDate') {
            hostedFieldsInstance.focus('cvv');
    }
}

And here’s the on focus function for hosted field:

hostedFieldsInstance.on('focus', function(event) {
    var field = event.fields[event.emittedBy];
    $(field.container).next().addClass('focus');
});

While this code works as expected on desktop browsers (Chrome, Safari, Opera etc.), there is a problem on Mobile Safari with this. When hostedFieldsInstance.focus is called the focus field is not changed although the on focus function is still called which can be seen when the field label changes its position (see attachment) and also testing with breakpoints in dev console shows the same.

Steps to reproduce the issue. ( Assuming that the order of fields is: number, exp. date, CVV )

  1. On credit card hosted fields click inside exp. date field and type 2 chars.
  2. Delete chars so the field is empty
  3. Click in the CC Number field and Write a valid CC number
  4. When it’s asserted as valid it should change focus to the next hosted field. But it’s not.

If the user is filling out the Credit card field as first it works as expected. Although if the user gets back to the field and changes something it does not work the second time anymore.

Hope you will be able to look into this issue.

Thanks, Emīls

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
crookedneighborcommented, Jan 10, 2019

Just did some testing, and that looks like it did the trick. Aiming to get this out in a release next week.

Thanks @lgodziejewski !

1reaction
crookedneighborcommented, Jan 15, 2019

This is fixed in 3.42.0, thanks again @lgodziejewski !

Read more comments on GitHub >

github_iconTop Results From Across the Web

hosted-fields/external/hosted-fields.js - Documentation
@property {?HostedFields~hostedFieldsFieldData} fields.cvv {@link ... iOS Safari has a bug where inputs in iframes // will not dismiss the keyboard when ...
Read more >
(Sort of) Fixing autofocus in iOS Safari | by Tommy Brunn
Focusing a field does three things: Set focus styles. Scroll the page so the field is somewhere in the middle of the viewport....
Read more >
Xcode 13 Release Notes | Apple Developer Documentation
The Xcode 13 release supports on-device debugging for iOS 9 and later, tvOS 9 and later, and watchOS 2 and later. Xcode 13...
Read more >
Sips Hosted Fields
When an error occurs on the Sips Hosted Fields server and creation of documents or entry does not work. The data (named event...
Read more >
iOS and iPadOS 15: The MacStories Review - Part 17
We now get to my favorite addition to Safari for iPhone and iPad this year: native ... Some website colors just do not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found