Gilles
Gilles

Reputation: 1

Disable dynamically a jquery plugin

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

Upvotes: 0

Views: 1068

Answers (1)

Nina Zarina
Nina Zarina

Reputation: 61

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.

Upvotes: 4

Related Questions