Adding a 'response' to a server action repeat breaks the repeat

Not sure if bug, or intended behaviour… Need some advice:

I have a form that is sending 2 arrays of information to a server action.
The server action loops through the values with a ‘repeat’.

Everything works as expected, however when I add a ‘Response’ it will only perform that repeat action one time.
When I disable it it’ll repeat the correct amount of times.

It seems like the ‘response’ is telling the server action that it’s done?
Is there a way around it? I want to display on the front-end that the form submit has failed or succeeded.

Hello,
The response step returns the response and then stops the server action from executing the steps after it.

Maybe you want to take it out of the repeater.

Hey @Teodor

Thanks!
I have an if statement

That is responding an error or a success message back to the client.
How can I do that in this case?

Example:
It’s trying to add 2 records, and I want to show 2 toasts:

  • The first one fails (I want to display a toast error on page - by sending the response to the page)
  • Second one succeeds (I want to display a toast ‘success’ on page)

Edit:
Only thing I can think of right now is to create an array in the server action, and then output that at the end of the server action OUTSIDE of the repeat?

So you are using responses just to show a toast on the page?
If that’s the case … just use a setvalue for the else step instead and check its value on the front end.

Yes just from one of your tutorials :smiley:

Okay so I’m using a setvalue for the steps:

But how can I pick that binding on the front-end?

Not sure how is your server action structured exactly, but you can try: serverconnect1.data.setvalue_name

The server connect is bound to the form: if I replace serverconnect1 with the form name (I guess that’s the way?) it’s giving me nothing in the toast.

But I also noticed in the devtools that the response of the server action is actually not giving me any of the vars.

The outputs are definitely on though. Am I doing something wrong?

Do your repeat steps have output enabled?

:man_facepalming: Yeah that fixed some things :wink: image

Last question:
It’s only showing me one toast though.
I have to put the toast in a repeat for every value or is there an easier way? (Right now you can see that it’s taking repeat[0] and repeat_for_courses[0])

I am not completely sure i understand the structure of your server action and what are you doing exactly and how many toast need to be displayed / where / why, so i can’t really answer your last question.

Okay let me simplify:

I have 3 tables:

  1. Users
  2. Courses
  3. Users_courses - One record in this table links a user to a course. If they’re linked together that means that the user can access that course

Goal: I need a form where I multi-select users and courses, on submit it’ll add records to users_courses for every course+user combination that doesn’t already exist.

The server action:

  1. Repeat over every user that’s sent via the form
  2. For each user, repeats over the courses that are sent via the form
  3. If the course+user combination exists: setvalue "course is already assigned"
  4. If the course+user combination doesn’t exist: `database insert into users_courses AND setvalue “course succesfully assigned”

This is working perfectly, I just want front-end information

Now example:

  1. I select 5 courses, 3 users.
  2. 1 of those users already has those 5 courses assigned
  3. After form submit I want to see something on the page like: “10 courses assigned, 5 failed”