#newb1

1 messages · Page 1 of 1 (latest)

grizzled spadeBOT
tardy zephyr
#

hi! do you have more context?

neat basin
#

probably the most important context is i don't know what i'm doing as a preface

#

i assumed this would go after card mount is completed

#

what i want is autofocus, seems not possible

#

docs seem indicate event listener is required, not sure how to do that with cardElement.focus();

tardy zephyr
neat basin
#

that shows " card.focus();", that's not what's in the docs

#

why does card.focus(); work if the docs say to use cardElement.focus();

tardy zephyr
#

it's the same thing

#

it's a variable name, I called it card, the docs called it cardElement I could have called it pineapple

#

it's whatever you assign to the left side of x = elements.create('card' ...)

neat basin
#

will try that then, thanks

#

didn't work

#

var card = elements.create('card', {style: style});
card.mount($cardElement[0]);
card.focus();

#

i assume i'm doing it wrong

tardy zephyr
#

maybe wait for it to have mounted and finished before calling it.

#
card.on('ready', function(event) {
    card.focus()
})
neat basin
#

tried that like so:

#

var card = elements.create('card', {style: style});
card.mount($cardElement[0]);
card.mount('#card-element');
card.on('ready', function(event) {
card.focus()
});

#

is this correct?

#

(didn't work)

tardy zephyr
#

worked for me

#

do you have a full example?

neat basin
#

oh heck hang on, did it on the wrong page

#

so didn't work but

#

the code is from a form called quform

#

with a stripe integration instruction

#

(works fine)

#

but the focus line you're adding is after a line that is different

#

theirs is

#

var card = elements.create('card', {style: style});
card.mount($cardElement[0]);

#

while yours is

#

card.mount('#card-element');
card.on('ready', function(event) {
card.focus()
})

#

the mount lines are different

#

i'm guessing that's what's preventing focus from happening as expected?

tardy zephyr
#

the code I wrote is equivalent

#

I'd suggest reaching out to the maintainer of that wordpress plugin for help really since they are the developer here closely working with the Stripe integration

neat basin
#

ok thanks