The problem is that the function that you unbind, is not that same the
you bind, although they are equal.
Try this:

(function($) {

  $.fn.checkForm = function(action){
    if (action == "add")
       return this.bind( 'submit', this.checkForm.handler );
    if (action == "remove")
       return this.unbind('submit', this.checkForm.handler );
  };

  $.fn.checkForm.handler = function() {
      return false;
  };

})(jQuery);

Cheers

--
Ariel Flesler
http://flesler.blogspot.com


On 2 abr, 16:56, Marc R <[EMAIL PROTECTED]> wrote:
> I'm kinda of a begginer on JQuery and I'm writing my first plugin.
> The plugin should handle form validation, in which I want to be able to
> enable or disable validation.
>
> The simplified version is like this:
>
> (function($) {
>   $.fn.checkForm = function(action) {
>
>     function validateForm() {
>           return false; // dont submit form, just that simple for this
> example
>     };
>
>     return this.each( function() {
>       if (action == "add")
>             $(this).bind("submit", validateForm); // add validation for the
> form
>
>       if (action == "remove")
>             // here I want to remove the validation from the form
>             $(this).unbind("submit", validateForm); // This is NOT working
>     });
>   };
>
> })(jQuery);
>
> after calling $('#myForm').checkForm('add') it wont submit
> but
> after calling $('#myForm').checkForm('remove') it still wont submit
>
> If I use $(this).unbind("submit"), it works, but removes all behavior
> attached to the event, and there I only want to remove that given behavior.
> Appreciate any help.
> --
> View this message in 
> context:http://www.nabble.com/unbind-especific-function-not-working-tp1645002...
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to