views:

30

answers:

2

Hi,

Currently I am using Jeditable version 1.6.1 in my project. I am trying to use the onkeyup event for validating user entered values in the input text field. When i am trying to use onkeyup event, it is not working. I am not sure whether Jeditable supports this event or not. Could you please help me with this problem?

Regards PJ

A: 

This worked for me.

$.editable.addInputType('dernumber', {
            element: $.editable.types.text.element,
            plugin: function (settings, original) {
                $('input', this).bind('keypress', function (event) {
                    return numbersOnly(event, false);
                });
            }
        });


$('.loremipsum').editable('http://www.example.com/save.php', { 
    type      : 'dernumber',
    cancel    : 'Cancel',
    submit    : 'OK'
});
Jon Connor
A: 

And this would the the helper method that validates whether or not the key is a number:

var numbersOnly = function (e, decimal) {
            var key;
            var keychar;

            if (window.event) {
               key = window.event.keyCode;
            }
            else if (e) {
               key = e.which;
            }
            else {
               return true;
            }
            keychar = String.fromCharCode(key);

            if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
               return true;
            }
            else if ((("0123456789").indexOf(keychar) > -1)) {
               return true;
            }
            else if (decimal && (keychar == ".")) { 
              return true;
            }
            else
               return false;
         };
Jon Connor