[dokuwiki] Re: [OFFTOPIC] odd addEvent problem

  • From: Andreas Gohr <andi@xxxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Wed, 02 Aug 2006 09:29:24 +0200

Michael Klier writes:

Hi folks,

sorry for this totally dokuwiki unrelated post but maybe one of you can
help me.

It's about a DokuWiki plugin using DokuWiki's script libs. I think it's pretty ontopic :-)


Lets see if I understood your code correctly. Your HTML looks like this:

<form class="cal_tool_btn">
 <input type="hidden" class="arg" name="foo" value="bar" />
 <input type="hidden" class="arg" name="bar" value="baz" />
 <input type="submit" class="button" />
</form>

This defines a single button. For multiple buttons you have multiple forms like this.

If this is the case your code looks correct to me.

The odd thing is that every Button gets the arguments of the last button
attached, so clicking on any of these buttons results in the same action.

I guess there may be something wrong in your calendar.show() method. Do you cancel the original form submit by returning false? Is the argv still correct when calendar.show is called? Eg. when you put an alert(argv) in calendar.show do you get different outputs for different buttons or is it all the same?


My last guess is that there is a problem with using argv in the closure of addEvent. In my opinion it should work the way you do it, but closures are a bit tricky. It might be that the argv you use in the closure keeps changing it's value while the loop runs. You might wanna try this (untested and maybe stupid):

attachToolEvents: function(obj) {
  ...
        // attach the Event
        calendar.buttonAttach(button,argv);
  ...
},

buttonAttach: function(button,argv){
   addEvent(button,'click',function() { return calendar.show(argv); });
},

The idea is to force the argv to be out of the loop scope into the buttonAttach function scope. No idea if this really changes anything.

I remember juggling with evals in the toolbar builder because of a similar problem.

Andi


-- DokuWiki mailing list - more info at http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: