0

I use the jquery numeric plugin to allow only numbers to be typed in some fields.

$("input.numeric").numeric();

I want to disable this function dynamically in some cases, to allow the user to type others characters (i.e. letters). I tryed to use the unbind() or undelegate() functions without success.

Does anyone know the solution ? Thanks

2
  • How did you use .unbind()? The numeric plugin just seems to bind a keypress handler to the input, so $("input.numeric").unbind(); should remove that (and every other) handler. Commented May 19, 2010 at 13:06
  • Thanks for your help. Finaly, I found this solution : $('#my_elt').unbind('keypress').unbind('blur'); I unbind all events used by the plugin. Commented May 19, 2010 at 13:41

1 Answer 1

4

This plugin contains function removeNumeric();

And It's almost correct. At first you should add a little fix in jquer.numeric plugin:

insert unbind("keyup", $.fn.numeric.keyup) at removeNumeric function

$.fn.removeNumeric = function()
{
  return this.data("numeric.decimal", null).data("numeric.negative",
  null).data("numeric.callback", null).unbind("keypress",
  $.fn.numeric.keypress).*unbind("keyup",
  $.fn.numeric.keyup)*.unbind("blur", $.fn.numeric.blur);
}

Well, and after that, you could try $("input.numeric").removeNumeric(); Works fine for me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.