Keyboard icon indicating copy to clipboard operation
Keyboard copied to clipboard

Disabling ios keyboard when init keyboard on dynamically added input

Open kerv opened this issue 12 years ago • 8 comments

When initializing the keyboard with an input that is dynamically added to the page, the iOS keyboard appears for a brief second and then disappears. It is as if the code focuses the input while the keyboard is initializing. This occurs even if the input is added as readonly or disabled.

I'm building a page that adds several inputs and initializes the keyboard on all of them. For each one, the ios keyboard appears briefly and then shows the mottie keyboard. It's visually rather annoying :).

Any ideas? http://jsfiddle.net/kerv/hyc1x50b/3/

HTML

<div id="testDiv">   
</div>
<input type="button" id="addButton" />

JS


        $(document).on('click', '#addButton', function () {
            var appendString = '<input type="text" name="newField" >';

            $(appendString).appendTo('#testDiv').keyboard();


        });

        $(document).ready(function () {
            $('#test').keyboard();
            //
        });

kerv avatar Aug 06 '14 22:08 kerv

Hi @kerv!

Honestly, I'm not sure what to tell you... I'll had to snag my old iPad to test that demo (v5.1 Safari).

The initial demo you sent appears to open the iOS keyboard on both the in-place input and dynamically added inputs. Though, when I set the lockInput option to true, it was working as expected, e.g. no iOS keyboard popped up at all (demo).

Maybe stuff has changed in newer versions/devices? I don't own any other iOS devices to be able to test this.

Mottie avatar Aug 06 '14 23:08 Mottie

Hi Rob,

Thanks for looking into this. I tried your demo on my iPad and it still happens on latest Safari. Right as soon as you click the Add button, if you look closely at the bottom of the screen the iOS keyboard appears for about 0.2 seconds. It's really quick. Sometimes it actually is barely noticeable, but if you change the code to append and keyboardtize 5 or 6 inputs you notice it a bit more.

I spent a few hours looking through your init code but no luck yet. It's something that iOS must do when attaching an input to the page. The only thing I thought I could do was possibly write a "reset" bindings command, whereby I could add my own classes/popup attributes to an input manually and then call this "reset" bindings (by passing in the jquery selector of the input) and perhaps at this point, it would work as intended. I'm not 100% sure though.

I'll keep digging and let you know if I find anything. Other than that, your keyboard works great on the iPad as long as you initialize things right on page load the very first time.

Regards, Kev

kerv avatar Aug 07 '14 04:08 kerv

Oh I think I finally found a solution (source)! (demo)

If you set both the lockInput option to true and the input's enabled property to false, the iOS keyboard doesn't open... as least not on my old iPad.

$(function () {
    $('#test')
        .prop('enabled', false)
        .keyboard({ lockInput: true });
});

You have to set both; but I think the lockInput isn't setting the readonly attribute properly since I don't see that property set.

Mottie avatar Aug 07 '14 12:08 Mottie

HI Rob,

Yep - still doesn't work on the latest iPad. It is so subtle for when the iOS keyboard, it literally flickers about 10px at the bottom of the iPad screen and then disappears. Sometimes it is so fast you don't even notice and other times it is slower.

It's more apparent when you add multiple inputs at once in the add button, even with the prop('enabled', false) in there. http://jsfiddle.net/kerv/hyc1x50b/11/

I'm still investigating here.

kerv avatar Aug 07 '14 14:08 kerv

I have a custom layout which uses preview and lockInput: true. In jquery.keyboard.js, after line 336 I added

.attr('readonly', 'readonly')

which solved this issue for me

mattriverm avatar Oct 01 '14 08:10 mattriverm

Dear all who can see this email,

Hello and Sorry to send an email in this group that is not related to the Keyboard project.

Actually I want to consult how to make a web application that is a online editor.

The idea is I can get the JSON response from the server via Http request as follow

  1. Startup [CLI.req] http://ip.addr:port/oledit.startup?keyd=&startd=&width=&height= [SRV.ret] On every one of following case the startup failed, and return false by {"result":"failed"} keyd not present keyd found, startd or width or height present keyd not found and startd not found width and height can not be sure otherwise return success with more startup infos. { "result" : "OK", "width" : 640, "height" : 480, "srv_ip" : "192.168.123.45", "srv_port" : 29150, "view_addr" : "rtmp://192.168.100.200/edit/vvvvvv", "step_addr" : "rtmp://192.168.100.200/edit/ssssss", }

  2. Resouce list [CLI.req] http://srv_ip:srv_port/resource.list?keyd=<ONE_KEY> [SRV.ret] if keyd not exist, return false°£{"result":"failed"} else { "result" : "OK", "filelist" : [ [ "aaaaa.mp4", "0001" ], [ "bbbbb.flv", "0002" ], [ "ccccc.mp4", "0003" ], ] } file list contains [filename, file_id] tuple.

  3. Resouce stream [CLI.req] http://srv_ip:srv_port/stream.list?keyd=<ONE_KEY>&fileid=<FILE_ID> [SRV.ret] if keyd not exist or parse failed, return false°£ else { "result" : "OK", "stream_list" : [ [ "video:0", 1000.343, "video" ], [ "audio:1", 1000.346, "audio" ], ] } stream list contains [stream_name, duration, stream_type] tuple.

  4. Step play [CLI.req] http://srv_ip:srv_port /edit.step?keyd=<ONE_KEY>&pos=<TIME_IN_SECONDS> [SRV.ret] if keyd not exist or seek failed, return false°£ else { "result" : "OK" }

    one should play the "step_addr" before send this request

How can I use this JSON response to make the application work? At least I should have some features like cut the video and mix the clips that I cut.

Thank you for your attention for this issue. This application is very important for me. And very urgent, I only have 16 days to make this JSON interface work.

I am looking forward to getting some advices from you.

Thank you!

On Wed, Oct 1, 2014 at 4:45 PM, mattriverm [email protected] wrote:

I have a custom layout which uses preview and lockInput: true. In jquery.keyboard.js, after line 336 I added

.attr('readonly', 'readonly')

which solved this issue for me

— Reply to this email directly or view it on GitHub https://github.com/Mottie/Keyboard/issues/295#issuecomment-57435185.

buildAll avatar Oct 01 '14 11:10 buildAll

Hi @mattriverm!

That bit of code already exists within the plugin - line 362

@buildAll I have no idea why you posted your online editor/JSON question here. Have you tried Stack Overflow?

Mottie avatar Oct 01 '14 12:10 Mottie

An update. Latest iOS version (that was release Sept 19 2014) seems to fix the issue for us!

kerv avatar Oct 02 '14 18:10 kerv