# Event Handlers - Legacy and Dynamic Update

**URL:** <https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147>\
**Category:** Ask the community\
**Tags:** wix-studio, code\
**Created:** [September 28, 2024, 12:03pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147 "2024-09-28T12:03:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![armkhachatryan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/armkhachatryan/32/10354_2.png) [@armkhachatryan](https://forum.wixstudio.com/u/armkhachatryan)\
**Post date:** [September 28, 2024, 12:03pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/1 "2024-09-28T12:03:52Z")

</div>

Hello everyone,

Recently there was an update for the event handlers, now they are legacy and dynamic. See [here](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/frontend-code/reacting-to-user-actions-using-events)

After this update there is an issue:

Upon experimenting, I can confirm that the repeater item selector $item does not select the correct item from the database.

For example, $item(‘#examsessionsDB’).getCurrentItem().fieldName always returns the value of the first item of repeater.

Code example:

```javascript
$w('#sessionsrepeater').onItemReady(($item, itemData) => {
    console.log($item('#examsessionsDB').getCurrentItem().fieldName) //needs to log the corresponding repeater item, but always return the first item
})

```

Moreover, the legacy way does the same:

```javascript
export function register_click(event) {
    let $item = $w.at(event.context)
  console.log($item('#examsessionsDB').getCurrentItem()) //needs to log the corresponding repeater item, but always return the first item
}

```

Please, help me to get this sorted.

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [September 28, 2024, 2:48pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/2 "2024-09-28T14:48:48Z")

</div>

You’re using `getCurrentItem` wrong, accessing it through the repeater’s `$item` would not matter, it’s outside the repeater anyway, that’s the dataset isn’t it?

Just use `console.log(itemData.fieldName)`

---

<div class="post-metadata">

**Author:** ![armkhachatryan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/armkhachatryan/32/10354_2.png) [@armkhachatryan](https://forum.wixstudio.com/u/armkhachatryan)\
**Post date:** [September 28, 2024, 3:37pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/3 "2024-09-28T15:37:14Z")

</div>

Dear @DeanAyalon ,

Thank you for your response.

I am sure it has to work like that, as I have already built more than 3 websites and used that on multiple places and it works how it should.

Check the 2nd example, this one:

> [@armkhachatryan](#):
>
> ```javascript
> export function register_click(event) {
> let $item = $w.at(event.context)
> console.log($item('#examsessionsDB').getCurrentItem()) //needs to log the corresponding repeater item, but always return the first item
> }
> 
> ```

Isn’t it the correct approach? I am sure it is and it just sopped working, Right now I have a website on which it works, both for the first and 2nd examples.

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [September 28, 2024, 3:42pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/4 "2024-09-28T15:42:19Z")

</div>

Again, let me confirm - Is `#examsessionsDB` a Dataset?

This dataset only exists once, it does not repeat with the repeater, so no matter what you do, `$item('#examsessionsDB')` returns the same element - The dataset

When running `getCurrentItem()` on a dataset showing multiple items, it will simply return the first one

That is definitely not what you wanted is it?

It does not matter how many websites you built using some tool incorrectly, even if it has worked previously

Now, if you want to get the data of an item in the repeater, it is passed as the second argument to the function you give the event handler

```js
$w('#someRepeater').onItemReady(($item, itemData) => { ... })

```

That’s the `itemData` you’re defining, just use it

If you don’t just want to log the item’s data, then let’s go back to the question - What is it you want to achieve?

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [September 28, 2024, 3:42pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/5 "2024-09-28T15:42:56Z")

</div>

Would you show me the websites in which this works and their code?

---

<div class="post-metadata">

**Author:** ![armkhachatryan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/armkhachatryan/32/10354_2.png) [@armkhachatryan](https://forum.wixstudio.com/u/armkhachatryan)\
**Post date:** [September 28, 2024, 4:55pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/6 "2024-09-28T16:55:00Z")

</div>

Dear @DeanAyalon,

Here is a code snippet from the same website which works as expected:

```javascript
export function examsrepeater_itemReady($item) {
    if ($item('#examsessionsDB').getCurrentItem().format === "Digital") {
        if (wixWindow.multilingual.currentLanguage === "hy") {
            $item('#tooltip').tooltip = "Ուշ գրանցման վճար՝ Չի սահմանվում"
        }
        if (wixWindow.multilingual.currentLanguage === "en") {
            $item('#tooltip').tooltip = "Late entry fee: Not available"
        }
        if (wixWindow.multilingual.currentLanguage === "ru") {
            $item('#tooltip').tooltip = "Плата за позднюю регистрацию: Не доступен"
        }
    }
    if ($item('#examsessionsDB').getCurrentItem().format === "Paper-based") {
        dateconvert(new Date($item('#examsessionsDB').getCurrentItem().lateEntryDate))
            .then((date) => {
                if (wixWindow.multilingual.currentLanguage === "hy") {
                    $item('#tooltip').tooltip = "Ուշ գրանցման վճար՝ " + date
                }
                if (wixWindow.multilingual.currentLanguage === "en") {
                    $item('#tooltip').tooltip = "Late entry fee: " + date
                }
                if (wixWindow.multilingual.currentLanguage === "ru") {
                    $item('#tooltip').tooltip = "Плата за позднюю регистрацию: " + date
                }
            })
    }
}

```

You can check the screen recording of the live page [here](https://drive.google.com/file/d/1bOJ_wHvURKPHl1kIgMK1PlWetr2n-Cid/view?usp=sharing)

Any thoughts on this?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [September 28, 2024, 5:03pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/7 "2024-09-28T17:03:25Z")

</div>

It’s intriguing that it works, I’ll give you that…  
As for why, I don’t know, because it honestly shouldn’t 😅

Anyway, have you tried using `itemData` instead? That is precisely what it was made for after all

---

<div class="post-metadata">

**Author:** ![armkhachatryan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/armkhachatryan/32/10354_2.png) [@armkhachatryan](https://forum.wixstudio.com/u/armkhachatryan)\
**Post date:** [September 28, 2024, 5:05pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/8 "2024-09-28T17:05:16Z")

</div>

Also,

Imagine you have a repeater, with a button in the repeater item, and you want to get that repeaters data on button click, this was the way to achieve it:

```javascript
export function selectexambutton_click(event) {
    let $item = $w.at(event.context)
    console.log($item('#examregistrationsDB').getCurrentItem())
}

```

Now this is not working as well.

As well as, the new way:

```javascript
$w('#selectexambutton').onClick((event) => {
    let $item = $w.at(event.context)
    console.log($item('#examsessionsDB').getCurrentItem())
})

```

not working either.

---

<div class="post-metadata">

**Author:** ![armkhachatryan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/armkhachatryan/32/10354_2.png) [@armkhachatryan](https://forum.wixstudio.com/u/armkhachatryan)\
**Post date:** [September 28, 2024, 5:06pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/9 "2024-09-28T17:06:25Z")

</div>

> [@DeanAyalon](#):
>
> As for why, I don’t know, because it honestly shouldn’t 😅

It should, it is in the documentation, as well as in older post questions, answered by Wix.

---

<div class="post-metadata">

**Author:** ![armkhachatryan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/armkhachatryan/32/10354_2.png) [@armkhachatryan](https://forum.wixstudio.com/u/armkhachatryan)\
**Post date:** [September 28, 2024, 5:06pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/10 "2024-09-28T17:06:59Z")

</div>

@DeanAyalon check this one, what is the right approach if not like this?

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [September 28, 2024, 5:08pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/11 "2024-09-28T17:08:36Z")

</div>

```js
$w('#repeater').onItemReady(($item, itemData) => {
    $item('#button').onClick(someFunction)
})

```

---

<div class="post-metadata">

**Author:** ![armkhachatryan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/armkhachatryan/32/10354_2.png) [@armkhachatryan](https://forum.wixstudio.com/u/armkhachatryan)\
**Post date:** [September 28, 2024, 5:08pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/12 "2024-09-28T17:08:56Z")

</div>

Check this out:

 ![Screenshot 2024-09-28 at 21.07.57](https://us1.discourse-cdn.com/wix/original/3X/9/4/94a7e56ed629e397435d977a1426f555d5bc88ca.png)

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [September 28, 2024, 5:09pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/13 "2024-09-28T17:09:23Z")

</div>

Could you source where in the docs Wix shows `$item('#dataset').getCurrentItem()` as opposed to `itemData` please?

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [September 28, 2024, 5:10pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/14 "2024-09-28T17:10:21Z")

</div>

Interesting… Never seem that syntax… Maybe it can deduce the context using $item…

Still, have you tried using `itemData`?

---

<div class="post-metadata">

**Author:** ![armkhachatryan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/armkhachatryan/32/10354_2.png) [@armkhachatryan](https://forum.wixstudio.com/u/armkhachatryan)\
**Post date:** [September 28, 2024, 5:10pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/15 "2024-09-28T17:10:22Z")

</div>

Yes, okay, but see this:

> [@armkhachatryan](#):
>
> Check this out:
> 
> ![Screenshot 2024-09-28 at 21.07.57](https://us1.discourse-cdn.com/wix/original/3X/9/4/94a7e56ed629e397435d977a1426f555d5bc88ca.png)

---

<div class="post-metadata">

**Author:** ![armkhachatryan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/armkhachatryan/32/10354_2.png) [@armkhachatryan](https://forum.wixstudio.com/u/armkhachatryan)\
**Post date:** [September 28, 2024, 5:11pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/16 "2024-09-28T17:11:56Z")

</div>

Yes I did, it works, but now i just need to update all the codes in all the websites, beacuse they are stopping to work.

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [September 28, 2024, 5:13pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/17 "2024-09-28T17:13:12Z")

</div>

At least you got it working, that syntax makes more sense and uses a lot less computing anyway, so it’s a one-time change and you’re done

---

<div class="post-metadata">

**Author:** ![armkhachatryan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/armkhachatryan/32/10354_2.png) [@armkhachatryan](https://forum.wixstudio.com/u/armkhachatryan)\
**Post date:** [September 28, 2024, 5:14pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/18 "2024-09-28T17:14:40Z")

</div>

I really want the old way to work, and it should work, because these are in the documentation, and there is no announcement that it will stop working and that we need to update all the codes.

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [September 28, 2024, 5:19pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/19 "2024-09-28T17:19:15Z")

</div>

Agreed, still, if we look at what. actually happens, the item data is passed to the onItemReady function.  
So it’s already there, therefore, using the getCurrentItem function for every item is redundant, and simply takes a lot of computation, running a function that retrieves data we already have

As for the syntax, I am not sure what may be causing it to not work on one page while functioning properly in another, but I’d stay away from it either way, especially as the whole static syntax is about to be deprecated

---

<div class="post-metadata">

**Author:** ![armkhachatryan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/armkhachatryan/32/10354_2.png) [@armkhachatryan](https://forum.wixstudio.com/u/armkhachatryan)\
**Post date:** [September 28, 2024, 5:21pm UTC](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147/20 "2024-09-28T17:21:42Z")

</div>

Yes, agreed.

Anyway, contacted Velo support, once I get answer, I will update here!

Thank you for your prompt replies and support, @DeanAyalon!

[Next page](https://forum.wixstudio.com/t/event-handlers-legacy-and-dynamic-update/63147.md?page=2)
