cocoonjs

Cocoonjs programmatically display soft keyboard


Just starting to look at cocoonjs and tried the canvas demo from their tutorial using the launcher app.. I was wondering though is there a way to bring up the soft keyboard on mobile when opening an app (without a text input on screen, or perhaps with one that is hidden)?


Solution

  • If you are using the newest launcher and lib, you should be able to do that via this code:

    Cocoon.Dialog.showKeyboard({ 
       type : Cocoon.Dialog.keyboardType.TEXT,
    },{
       insertText: function(inserted) { text+= inserted; console.log(text);},
       deleteBackward: function() {text = text.slice(0, text.length -1); console.log(text);},
       done : function(){ console.log("user clicked done key") },
       cancel : function(){ console.log("user dismissed keyboard") }
    });
    

    You can then hide the keyboard via this code:

    Cocoon.Dialog.dismissKeyboard();
    

    If you get an error that "deleteBackward" is undefined, go to the cocoon.js file search for this line:

    [params, insertCallback, deleteBackward, doneCallback, cancelCallback], true);
    

    and replace it with this one:

    [params, insertCallback, deleteCallback, doneCallback, cancelCallback], true);