Condition before Mouse click

I still have a problem to be solved
With Dynamic Events / Click I created an action that provides for some updates to the database and to carry out the transition to a new page
But, since it is availability, it would be necessary to make a new verification just before the action
I would therefore need to insert a condition that provides for checking and in the positive case concludes the action, or if negative blocks the action, displays an alert and provides the reset of the page.
In the action editor I do not find this possibility
Does anyone know something?

Dynamic event on server connect form submit, with modifier preventDefault to prevent form submit, and you run the flow you want to do those checks, if it’s all good you do a form submit and tick the checkbox to skip the modifier (so the form isn’t prevented from being submitted again)

Honestly, I don’t quite understand this procedure.
I have a button (present in each row of a table of records)
The button loads an action that updates two different tables in the database
So far everything works
But to avoid problems, I would like the Availability Query to be reset and the data to be compared when the button is clicked.
If the check is OK, the procedure ends
If the control is KO Alert, abandonment of the procedure and reset of the page
I tried clicking on Modifiers / Prevent Default
But I don’t know how to proceed here
Is there an example somewhere or a short tutorial?

Sorry about that, I wasn’t at the computer and the answer was a bit too technical and generic (not very specific to your case), perhaps may not even fit you. You can ignore it for now

I don’t understand this :frowning: What is Availability Query?

@Teodor @George
I’m going crazy with a problem that I can’t solve and I wasted too much time
In a table for each record there is a button that cluccando updates the database by decreasing the availability of two fields
So if the request is 5 seats, the button is visible only if the availability is at least 5 seats
But now it may happen that in the meantime the availability has decreased for operations carried out by other users.
For example they are no longer 5 places available, but 4

And here my problem. For which I attempted in all ways
I would like to click on the button to reread the current availability and in case of insufficient availability an alert was displayed and the update operation was blocked, perhaps with a reload of the page

Is there this possibility?

Well you can just run a database query in the server action, check the available places using a condition and set a response to be returned to the front end. Use the response/status and show an alert on the specific event.

Hi Teodor
that’s what I tried to do, but it doesn’t work for me

The screenshot you posted really tells me nothing.
What i suggested it to place the query and the condition in the server action used to book your places, not in a flow. So the steps would be:

  • DB Query (filtered and returns the places)
  • Condition (checks the number of places if places >= &_POST.input value)
  • Then -> run the insert/update
  • Else -> Response step (use the appropriate 4xx HTTP status code)

Then on the front end run the alert/notification on the corresponding dynamic event of the server action / form.

But the problem is that at the opening of the page the availability query is read and the possibility of booking is allowed only if the disposability is sufficient for the request
This ok, it works perfectly.
The problem is that if the user passes some time, the available available in the meantime can be changed, and the query provides incorrect data

That’s why the solution i proposed will always work, as it will always check the availability right before the update step.

But do I have to insert everything inside the click?

<button id="btn_upd" class="btn btn-success btn-sm w-100" dmx-hide="(posti &lt; sc_biglietto_populate.data.qry_biglietto_populate.posti) || (cani &lt; sc_biglietto_populate.data.qry_biglietto_populate.cani)" dmx-on:click="sc_update_viaggio.load({idviaggio: IDviaggio, posti: (posti - sc_biglietto_populate.data.qry_biglietto_populate.posti), cani: (cani - sc_biglietto_populate.data.qry_biglietto_populate.cani)},true);sc_update_biglietto_andata.load({idviaggio_andata: IDviaggio, uuid: sc_biglietto_populate.data.qry_biglietto_populate.uuid, idbiglietto: sc_biglietto_populate.data.qry_biglietto_populate.IDbiglietto})">Orario partenza</button>

This is the first Query DB
Is correct Load or Reset?

Then if I do not convert in flow I can’t find the possibility of creating a condition

No, as i already explained:

So I have to create a new action, and then call it back to the click of the button?
Schermata 2023-07-11 alle 14.27.02

Schermata 2023-07-11 alle 14.31.38

No … add the query and the condition steps in the update server action, please make sure to read my posts. I can’t explain it more detailed than that.

1 Like

A little late but I understand
Thank you and excuse me

@Teodor

Hi Teodor
Sorry if I wasted some time yesterday, but I took a wrong turn and I struggled to get out
Now I have fixed the whole procedure and except for surprises everything seems to work.
But I have a problem to fix the exit from the condition (ELSE)
I entered Response 415
But apart from the fact that I honestly don’t know if it’s a correct code for my need, in case of a failed condition it doesn’t produce any result.
In practice I have a server action that manages the status and updates of the database. The action is called up on the page by SC and then by the Click button
I would like to display a clearly visible alert text and if possible with a reset of the page
Is there a tutorial on how to do it?
Thank you

Possibile response tutorial?

I would probably use a 409 error status in the response step in this case. On the front end call your notification or whatever action you need on error dynamic event.