iOS set focus on input

Hi there,

In my workflow, I use the block set focus on input. This works perfectly on my browser and android devices, but not on iOS. According to other forums Apple has an issue with that, but there are some workarounds to be done on the code. Does anyone know how to solve that via bubble?

Thanks,
Gabriela

3 Likes

Hello Gabriela,

If I remember well, it is a matter of font size inside. With a 14px font, it will not focuse anymore (I think it should be equal or more than 12px so as not to zoom)

1 Like

Hi, my problem is not with zoom. In the settings, i configured the app to not autozoom when clicked. The problem is the ā€œfocus on inputā€ does not focus on iOS

1 Like

bump, any solution for this? I have the same issueā€¦

1 Like

bump, any fix for this?

1 Like

bump, any fix for this?

3 Likes

Bump, any fix for this?

1 Like

This is actually a limitation in mobile Safari, which deliberately prevents programmatic focusing before the user has interacted with the page.

For further reading on the subject, hereā€™s a stackoverflow thread and a medium post.

2 Likes

Thanks, Marca for looking into my bug request. Iā€™ve experienced this with the google chrome browser on iPhone does this also explain this? The link says that it works in chrome?

2 Likes

FYI - Bubble is aware of this issue and thereā€™s an existing feature request covering it.

Has anyone figured out a workaround for this scenario, in particular for ā€œchatā€ pages? Itā€™s not a great experience to have to tap the input field after every sent message. (As per @chris19 above, this also does not work in Chrome.)

1 Like

Bump, any fix for this?

Iā€™ve seen workarounds elsewhere (not Bubble related) using Vue.js and other things I donā€™t technically understand. Anyone found a way to integrate into a Bubble project?

EDIT:
Test it here
https://setfocusioskeyboard.bubbleapps.io/version-test

So I think Iā€™ve figured it out. I had to resort to using javascript, so I can almost guarantee that someone who actually knows javascript can make a more elegant version of this, but hey if it works it works.

HOW TO KEEP iOS KEYBOARD ACTIVE/FOCUSED ON A TEXT FIELD IN BUBBLE:
To include javascript install the plugin called Toolbox. (Iā€™m sure other javascript plugins work as well, have not checked)
Screenshot 2023-01-26 at 17.39.53

Then to be able to connect javascript with bubble elements enable the ā€˜expose the option to add an ID attribute to HTML elementsā€™ option in settings in the General tab.

The problem I was trying to solve was for a user to be able to add several items into a database without losing the iOS keyboard after saving each item. I used an input form, a button, and a repeating group with a text element to display the data. (DB is called ā€˜Stepsā€™, the DB field the user is adding to is called ā€˜Actionā€™.) It looks like this:

Add an ID Attribute for both the input form and another for the button. Call them whatever you want. Example:

Input form id:
image
Button id:
image

Then in the buttonā€™s workflow add ā€˜Run Javascriptā€™

The javascript code I used:

 var saveButton= document.getElementById("save_step");
 var textInput= document.getElementById("input_step");

saveButton.onclick = function() 
{if (textInput.value !="") 
  {textInput.value = ""; }
{
        textInput.focus()
    }
}

Thatā€™s it. Well almost. For whatever reason, it doesnā€™t work the first time the button is clicked, but does work on all subsequent clicks. Not wanting to explain this to my users I found a workaround:

Turn off visibility on page load for input form:
image

Then have the user click the ā€˜saveā€™ button in order to display the text field.

Another workaround might work better in other apps, but in my case it really helps the UX feel native.

So there you have it. Hope this can be of use for more people.

5 Likes

For the last part to work well, consider adding ā€˜FieldName isnā€™t emptyā€™ as a search constraint. Nobody wants to look at an empty field.

1 Like

@oddddd

I think the script works only from the second click because it gets activated only after the first click.

Try to run the script on page load. Then it will work the first time you click the Save button.

I did a similar thing on my app and it works at the first click.

1 Like

@snowsnow

Thank you! That is way more elegant.

1 Like

You saved me a lot of time. Thank you.

@oddddd thank you man! this is very helpful!

@oddddd @snowsnow @ramasuarez @eagledev did you guys have to change the javascript code that you ran on page load?

not sure why, but tried to add the same script on pageload but first click still doesnā€™t work (while second click does work).

many thanks!

@davewliu
This plugin fixes the problem easily:
Open iOS keyboard (Apple iPhone) Plugin | Bubble.

thanks!

bought it, weirdly it doesnā€™t work for my app even after messing around for quite some timeā€¦ although the demo works.

guessing itā€™s user error :-T will reach out to the plugin author for ideas