Mottie / Keyboard

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

Submit #610

Closed heini23 closed 6 years ago

heini23 commented 7 years ago

Hi @Mottie,

I really love your script but have a huge newbie Problem. It would be so great if you can help me with it.

Im using your example code from "Custom Hex". If someone presses the green button it should send a submit request to the URL test.php. Do you know how I can solve this?

Thanks!


$(function(){
$('#hex')
    .keyboard({
        layout: 'custom',
        customLayout: {
            'normal' : [
                '0 1 2 3',
                '4 5 6 7',
                '8 9 test',
                '{bksp} {a}'
            ]
        },

        maxLength : 6,
        alwaysOpen: true,
        // Prevent keys not in the displayed keyboard from being typed in
        restrictInput : true,
        // activate the "validate" callback function
        acceptValid : true,
        validate : function(keyboard, value, isClosing){
            // only make valid if input is 6 characters in length
            return value.length === 6;
        }

    })
        });
Mottie commented 7 years ago

Hi @heini23!

If the input is inside of a <form> element, then the easiest thing to do is to use the accepted callback to submit the form.

accepted: function(event, keyboard, el) {
  // Don't submit an empty value
  if (el.value) {
    $("#myform").submit();
  }
}
heini23 commented 7 years ago

wow that was easy. It works perfect :D

Thank you so much!