These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:26 pm Advanced search

addEventListener with addRepetitionBlock?

Here you can discuss things related to HTML and the Web in general that do not fit in to other categories.

addEventListener with addRepetitionBlock?

Postby rendezvouscp » Wed Feb 20, 2008 9:29 pm

Hello. I've only been working with JavaScript for the past month or so, so this might be a very unintelligent question. If so, my apologies.

I'd like to be notified when a repetition block (for a certain template) is added. I'd also like to get the index number, but if that's not possible I can figure it out myself. What should I attach an addEventListener to?

I'm testing in Opera (9.25) and Safari with the WF2 JS library. Any help is GREATLY appreciated.
rendezvouscp
<h6>
 
Posts: 5
Joined: Wed Feb 20, 2008 9:22 pm

Postby zcorpan » Thu Feb 21, 2008 1:18 pm

Looking at the WF2 spec, I find these events related to the repetition model:

added
removed
moved
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden

Postby rendezvouscp » Thu Feb 21, 2008 3:16 pm

Thanks Simon. I think my new question is now regarding this line:

An added event with no namespace, which bubbles but is not cancelable and has no default action, must be fired on the repetition template using the RepetitionEvent interface, with the repetition block's DOM node as the context information in the element attribute.


If my template has an id of "items" then I'm expecting to be able to do the following in order to get feedback when a new repetition block has been added:

Code: Select all
document.getElementById('items').addEventListener('added', asdf(), false);
function asdf() {
   alert('repetition block added');
}


This, of course, isn't working for me. I'm guessing it's something I'm doing wrong, but I just don't know what. Again, help is greatly appreciated.

P.S. Yes, I'm aware that I can attach my function to the Add button and then just look up the last element in my list, or I could run through all of the elements again. However, I'd still rather do it with an event listener.
rendezvouscp
<h6>
 
Posts: 5
Joined: Wed Feb 20, 2008 9:22 pm

Fixed

Postby rendezvouscp » Fri Feb 22, 2008 9:35 pm

In the process of trying to do what I wanted through the Add button, I realized that the repetition block wouldn't be added until after the click event, so that wouldn't work. However, I tried the above solution again, and it worked fine for me. I'm guessing it I did something wrong before in my delusional state of infirmity. Here's what I ended up with (items is the id of the repeat template):

Code: Select all
var items = document.getElementById('items');
items.addEventListener('added', function() {}, false);
rendezvouscp
<h6>
 
Posts: 5
Joined: Wed Feb 20, 2008 9:22 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests