Mottie/Keyboard

CallBack custom function when keyboard does not accept key

Closed this issue · 6 comments

It is possible to restrict user input to accept only list of valid keys ( which are mentioned in keyboard layout). This can be done by setting restrictInput : true;

Now is there any call back which fires when the keyboard reject the user entered key. I want to show an alert to user that he is entering the wrong keyboard.

The code I am looking will be called as:

restricInputCallBack : function ( keyboard , event) { 
                                 alert ( " The  " + key + " is not valid" ); 
                                 }

Is above feature available ?!

Hi @afattahi54!

That sounds like a good idea! I'll have a patch available within the working branch shortly.

I named it restricted to keep the name short ;)

Use it as follows (example using the hex keyboard):

$('#hex').keyboard({
    layout: 'custom',
    customLayout: {
        'default' : [
            'C D E F',
            '8 9 A B',
            '4 5 6 7',
            '0 1 2 3',
            '{bksp} {a} {c}'
        ]
    },
    maxLength : 6,
    restrictInput : true, // Prevent keys not in the displayed keyboard from being typed in
    restricted : function(event, keyboard, el) {
        console.log( ' The "' + String.fromCharCode(event.keyCode) + '" key is not valid!' );
    },
    useCombos : false // don't want A+E to become a ligature
});

Thanks !

The solution sounds great.Could you please tell me ,When will the patch be ready to use?
I "really" need this one.

Thanks :-)

Hi @lilibit1985!

The patch is available if you download the code from the working branch. The only thing I haven't done is copy it to the master branch, document and label the code as the next update.

I have a bunch of stuff I'm working on, so I don't know exactly when I'll make it all available, then name it the next version.

Update: oops, I meant working branch.

Hi @Mottie ,

Thanks for your help,we will wait for the next release. :-)

Ok, this callback is available in 1.19.0. Thanks for your patience!