How to navigate to the previous or next item in a select component in one javascript

Hello,
I have two link buttons to respectively select the prior or the next item from a select component. The use case is:

  • The users select an initial value from the select component. (ie. Select 2 from [1,2,3])
  • When they click the "Previous" Link, the prior item in the select component is selected. (1 is being selected)
  • When they click the "Next" Link, the next item in the select component is selected. (Now 2 is being selected)

I originally created two javascript, so when the previousLink is clicked, it triggers the previousQuery, and when the nextLink is clicked, it triggers the nextQuery.
I would like to know if it is possible to put them together in one javascript by adding a logic saying if previousLink is clicked then ... and if nextLink is clicked then ...

Thank you in advance for the help.
Happy Retooling!

Hey @doris.l ,

Sounds like a job for triggeredById. Read more here.

In your query, you can determine which function to run (previous/next) based on the component that triggered that query.

Would that work for you?

2 Likes

Great idea there @minijohn :+1:

1 Like