How to: add different actions to buttons in repeater

I am quite new to corvid. very little coding experience…

On my site, I have a repeater with 6 containers. Each has an image and a button. The repeater is connected to a database named “INGREPPOMRÅDE”. In this dataset, label the button gets its text/label from the column id “title”. The buttons different labels are “BRÖST +”, “KROPP +” and so on.

I want each button, when clicked, to expand different sections under the section containing the repeater itself. These sections are already collapsed at loading. The different sections have id:s like “brostsektion”, “kroppsektion” etc.

I am totally at a anlost as to what to do as all buttons have the same ID and therefore execute the same action if I was to only add a OnClick function.

How can I get different expansions depending on the different labels in the dataset?

PLEASE PLEASE PLEASE help!!!

SZ

1 Like

First, please observe the policies and guidelines , and DO NOT USE ALL CAPS.

Understand that this forum is a community of Corvid developers and users where various topics are discussed and information shared. It is not a support site.

Explain what you are trying to do, what works, and what doesn’t. Also, add any code in a code block .

To learn about programming with Corvid, read the following articles that will help you start working with Corvid:

If you find that you are having difficulty with code and need assistance, you may want to check out the Wix Marketplace - it’s a place where you can look for Corvid experts for hire.

well as a wix user, I do expect to be able to ask other wix users for tips on problems I encounter while building my website. If someone has already experienced the same problem and found a solution I dont see the point in reinventing the wheel…

plus you answer is a bit strange, if you dont have a solution to add, perhaps not engage in the topic. Maybe someone else does want to help…

apoligiez for the caps though…

You wrote: " all buttons have the same ID and therefore execute the same action if I was to only add a OnClick function"

A good place to start would be the API section on Repeated Item Scope . This will explain how to select a specific instance of a repeating element. Once you understand how that works, you’ll be able to take the correct button action for each item.

Perfect! Thank you!

@zommorodi I did provide an answer which is precisely the solution that you need in the case that you presented in your post.

You can also see the Examples page for a number of examples that use Repeaters.

Rather a harsh response by the moderator. This guy was just asking for help, and he used all caps in all of just 3 words (unless you are counting his button labels.) This is an example of being reprimanded rather than helpful, in the guise of “help.” It is frustrating for newbies that there is a forum for developers, but no forum for non-developers, who post here because they don´t see anywhere else to ask and then get this type of response. Yes, you can call to get support and it is often very helpful, but that´s time consuming for users and it´s a cost for Wix. When I was with Squarespace I often just searched for the issue I was having and the answer was available online because another user at my level had asked and there was a helpful community who had already had the issue and posted about it, without having to generate a support request, and without being reprimanded and told I could pay for help. And oh yes, I know that this post violates guidelines but I think it needs to be said. And yes, I have raised this issue with support and through suggestion and other channels but it doesn´t get addressed.

1 Like

Reprimanded? First, the OP’s post is edited, so most likely they (or a moderator) edited the post to lowercase. Second, I was just pointing out what was what. The post wasn’t deleted, and I supplied material to help the user learn. Furthermore, I asked the OP to explain what he tried so far, what worked, what didn’t and so on.

Newbies are welcome to participate and learn here. Many of our advanced users were once newbies and the forum was instrumental in their advancement. Users who are willing to put in the effort, will find that the community will help. However, this is not the place to find someone to do your homework.

For those users who’s requirements are urgent and they don’t have the time to spend learning what they need, the Wix Marketplace is a great place to find help. And, the user can continue to learn and pick up where the consultant left off.

We are happy to get you pointed in the right direction, but you’ll need to take it from there. As questions or difficulties arise, we are here to help.

Also, note that the user seems to have been happy with the resolution of his issue. In his words, " Perfect! Thank you!". That’s what it’s all about.

Hello everyone !

@zommorodi , did you find the answer you were looking for? If so, could you share it with the rest of us? :pray:

@yisrael-wix , thank you for your help so far but, if you would allow some constructive feedback, I feel there are a few sub-optimal things going on with this support thread:
• the long article you redirect us towards seems to mention how to take repeater items link to different actions based on a connection between the repeater and a dataset by calling let $item = $w . at ( event . context ) ; however, the idea here is to rather have a different expand action which does not seem to be explained within the documentation you provided unless I’m mistaken ?
• The list of examples you shared do not return anything when filtered with “repeater expand”, “repeater”, or “expand”.
• You seem to have invested more time moderating the chat rather than detailing or looking for an answer
• The question is flagged as “solved” when the solution is not copy pasted within the thread. For me, sharing a lot of sources that do not clearly answer the question is the equivalent to redirecting us to Google or Wikipedia without having checked if what we seek was available

For anyone else arriving here, I’ll circle back once I found an answer to this. I think a mix of let $item = $w . at ( event . context ) and if statement based on a text content should do the trick ! :bulb:

Hi team,

This code works :tada:

The idea is to check one “fixed” element of your repeater item (in my case a text string) to decide what expansion action to take, let me know if you have questions and (hopefully) I’ll get a notification about it :raised_hands:

export function interview01ModuleButtons_click ( event ) {
let $item = $w . at ( event . context );

**if** ( $item ( "#interview01ModuleTitle" ). text  ===  "How to get a similar job" ){ 
    $w ( "#InterviewModule0101" ). expand (); 
} 

**if**  ( $item ( "#interview01ModuleTitle" ). text  ===  "Top resources and things to do to prep" ){ 
    $w ( "#InterviewModule0102" ). expand (); 
}     

**if**  ( $item ( "#interview01ModuleTitle" ). text  ===  "Education and work experience" ){ 
    $w ( "#InterviewModule0103" ). expand (); 
}                 

**else**  {  
    $w ( "#InterviewModule0104" ). expand (); 
} 

//console.log($item(“#interview01ModuleTitle”).text)
}

1 Like