Mottie / Keyboard

Virtual Keyboard using jQuery ~
http://mottie.github.io/Keyboard/
Other
1.78k stars 723 forks source link

Dont know if its an issue, but.... #627

Closed undefined-user-ctrl closed 6 years ago

undefined-user-ctrl commented 6 years ago

Hi,

I am using this options to restrict input, and its working fine.

restrictInput : true, restrictInclude : '( ) -',

But, for some reason, i need to be able to add an space via validation (called in beforeInsert method), and i cannot figure how to add it in 'restrictInclude' option.

How should i do that? I tried '( ) - ' (two spaces), and '( ) - {space}', but no lucky.

Btw nice plugin :)

Mottie commented 6 years ago

Hi @lucas-signorini!

Thanks, I'm glad you're finding the plugin useful!

Hmm, I guess there isn't anyway to add a space to restrictInclude option. The alternative is to add it to the built layout when the keyboard becomes visible (demo):

$(function() {
  $("#keyboard").keyboard({
    layout: "num",
    restrictInput: true,
    restrictInclude: "( ) -",
    visible: function() {
      var layout = $.keyboard.builtLayouts["num"].acceptedKeys;
      if (layout.indexOf(" ") < 0) {
        layout.push(" ");
      }
    }
  });
});

I'll see what I can do to make this process a bit easier.

undefined-user-ctrl commented 6 years ago

Hi @Mottie,

In my case i'm using a 'custom3' layout, just changed that in $.keyboard.builtLayouts["num"].acceptedKeys; and it worked like a charm :)

Thanks for quick reply!

Mottie commented 6 years ago

In v1.27.1, you can now add a space as follows (demo):

$(function() {
  $("#keyboard").keyboard({
    layout: "num",
    restrictInput: true,
    restrictInclude: "( ) - {space}"
  });
});

And updated docs.