#ron-paymentelement-focus
1 messages · Page 1 of 1 (latest)
no worries thank you, I think it may be something I have to solve in my code
As far as I know it doesn't allow you to focus a specific input. What are you trying to focus beyond just using https://stripe.com/docs/js/element/other_methods/focus and having us focus the first input field
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
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
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
Ah I see
hmm it says undefined, I think it's because the payment element is outside the scope of that function
paymentElement is just my variable name
you need to figure out how to access paymentElement in your own code yes
Ye I have the same, I'm just crap at javascript trying to figure it out
yours is this.paymentElement though it's different, and I don't know what your this. is. But you could try that at least
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
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
yay!
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
👋 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?
Ah I have email hidden
that makes sense
I thought it would focus the sort code at the top
billingDetails: {
email: 'never',
phone: 'never'
}
},```
I have this set
So it must be being focused in the background and I'm not seeing it
Hmm actually mine does focus on Sort
Test yours again?
I'm seeing it work just fine
Do you have a log in your ready function?
Ye I can see it firing
Add a log and make sure that it is getting hit inside that functino
because my loading becomes false
Ah okay
Hmmm
Try a hard refresh / reload the server?
Maybe something got cached?
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
I cannot figure this out, is there anything I can console.log to check what's going wrong?
Hmm
Not that I can think of. If you don't hide email does it focus on email properly?
No doesn't seem to make a difference
Hmm okay but same exact code works with Card?
no doesn't seem to work with anything
Oh
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
Sounds to me in that case like something is potentially stealing the focus here
Do you have a link where I can repro?
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
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
I think you're right
It may be the async method in vue not allowing it for some reason
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