#ron-paymentelement-focus

1 messages · Page 1 of 1 (latest)

lavish shoalBOT
hot notch
#

ron-paymentelement-focus

#

sorry still looking

smoky idol
#

no worries thank you, I think it may be something I have to solve in my code

hot notch
smoky idol
#

Isn't that for the elements API though?

#

I'm using the payment element iframe

hot notch
#

no that works for all Elements

#

I just tried locally and if you do this after the PaymentElement is ready it will focus the card number's input field for example

smoky idol
#
                    this.paymentElement = this.elements.create("payment", paymentElementOptions);
                    this.paymentElement.mount("#payment-element");
                    this.loading = false;
                    this.paymentElement.cardElement.focus();
#

I tried this and it doesn't work, am I doing it incorrect

hot notch
#

yeah you are doing it incorrect

#

1/ wht is .card element?
2/ you didn't wait for the element to be ready?

#
  console.log("FOCUS");
  paymentElement.focus();
});```
#

try this, it will work

smoky idol
#

Ah I see

#

hmm it says undefined, I think it's because the payment element is outside the scope of that function

hot notch
#

paymentElement is just my variable name

#

you need to figure out how to access paymentElement in your own code yes

smoky idol
#

Ye I have the same, I'm just crap at javascript trying to figure it out

hot notch
#

yours is this.paymentElement though it's different, and I don't know what your this. is. But you could try that at least

smoky idol
#

I'm using vue

#

so my payment element is declared as a data property

hot notch
#

I've never used Vue myself so I can't really help much unfortunately but hopefully something you or a colleague can help debug quickly

smoky idol
#

I've figured it out thank you. The function was changing the context of this to the function so I couldn't access my data anymore

#

I just changed it to this

this.paymentElement.on('ready', (event) => {

#

works now, thanks for the help

hot notch
#

yay!

smoky idol
#

Wait actually it doesn't seem to be working

#

should it autofocus the first input?

#

I have reordered payment methods so bacs direct debit comes before card is that my issue

copper garnet
#

👋 stepping in

#

It should focus the first input afaik

#

What are you seeing with BACS?

#

Should focus the Email field

#

Is that not what you see?

smoky idol
#

Ah I have email hidden

#

that makes sense

#

I thought it would focus the sort code at the top

copper garnet
#

Ah I would expect it to if email is hidden

#

Let me repro with BACS real quick

smoky idol
#
   billingDetails: {
    email: 'never',
    phone: 'never'
   }
},```
#

I have this set

#

So it must be being focused in the background and I'm not seeing it

copper garnet
#

Hmm actually mine does focus on Sort

#

Test yours again?

#

I'm seeing it work just fine

smoky idol
#

Ye it's not working

#

strange

copper garnet
#

Do you have a log in your ready function?

smoky idol
#

Ye I can see it firing

copper garnet
#

Add a log and make sure that it is getting hit inside that functino

smoky idol
#

because my loading becomes false

copper garnet
#

Ah okay

#

Hmmm

#

Try a hard refresh / reload the server?

#

Maybe something got cached?

smoky idol
#

Ye just tried still not working, I've just console.log payment element and it seems fine

#

Should this contain something? if .focus is used

copper garnet
#

Hmm let me check

#

Nope mine looks the same

smoky idol
#

I cannot figure this out, is there anything I can console.log to check what's going wrong?

copper garnet
#

Hmm

#

Not that I can think of. If you don't hide email does it focus on email properly?

smoky idol
#

No doesn't seem to make a difference

copper garnet
#

Hmm okay but same exact code works with Card?

smoky idol
#

no doesn't seem to work with anything

copper garnet
#

Oh

smoky idol
#

I just removed all my extra code and just had boilerplate payment element

#

It might be an issue with vue, but I don't see how, I can still see the fire event

copper garnet
#

Sounds to me in that case like something is potentially stealing the focus here

#

Do you have a link where I can repro?

smoky idol
#

ye just a second, let me push to the dev server

#

It may be easier If I give you my code, you'll have to fill out a long form to see the result

copper garnet
#

I mean your code should be fine if you have already logged out paymentElement and know the ready function is running.

#

It seems that something else is interacting with the input afaict

smoky idol
#

I think you're right

#

It may be the async method in vue not allowing it for some reason

copper garnet
#

Yeah I mean this code looks fine to me. I'm not intimately familiar with Vue so can't really speak to whether it is a Vue-specific thing