ajax - jquery plugin: what is wrong with $.fn. in my plugin? -


what wrong jquery plugin when make function inside plugin $.fn.

you can see mean here. have 2 forms , share same plugin,

     $(document).ready(function(){          $("#search-title").post_form_public();         $("#subscribe-email").post_form_public();      }); 

the first form won't working again when second form triggered.

it works fine if attach plugin 1 form only.

below more details inside plugin code,

post_form_public: function(options) {      // set default values, use comma separate settings, example:     var defaults = {         top:            250, // top of proceesing popup , result popup.         width:          400 // width of proceesing popup , result popup.     }      var options =  $.extend(defaults, options);     var o = options;      var $cm = this.submit(function(e){          var object = $(this);          // path attribute of action in form.         var target_postpath = object.attr('action');         var top = o.top;         var width = o.width;          // keep lines below checking.         alert($cm.selector);          // disable submit button won't click twice while ajax processing form.         // must use true or false jquery > 1.6.         $('input[type=submit]',$($cm.selector)).attr('disabled', true).css({opacity:0.4});          // post form .         $.post(target_postpath,object.serialize(),function(xml){              //process_posted(xml); // 2 forms work fine this!             $.fn.post_form_public.process_posted(xml); // not this!          });          return false;      });      // callback function proccesing deleted item.     //function process_posted(xml)     $.fn.post_form_public.process_posted = function(xml)     {          // enable submit button again after processing xml output.           // must use true or false jquery > 1.6.         $('input[type=submit]',$($cm.selector)).attr('disabled', false).css({opacity:1});      }  } 

but if make function without $.fn., these 2 forms work fine. how can use $.fn. , make multiple forms worked!?

or can see code here.

thanks.

the variable

$.fn.post_form_public.process_posted 

...can store 1 function. second time call plugin, overwritten. in form works, have function forms closure on value of $cm variable - , have 1 of these functions created each call post_form_public.

what's matter form of function worked?

one method store in post_form_public object might like:

if(!$.fn.post_form_public.process_posted) $.fn.post_form_public.process_posted = {}; $.fn.post_form_public.process_posted[$cm.selector] = function(xml) {   //... }; 

...and call within post callback with:

$.fn.post_form_public.process_posted[$cm.selector](xml); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -