Using a Flow to prevent double clicking?

I have an issue with a very small form that processes so fast that staff often double click and I get double entries in the database.

Can a flow be used to:

  • Hide the button on click
  • Run the Server Connect Action
  • Wait 3-5 seconds
  • Show button again

I have it set up now that when button is clicked it hides the button while processing. But ot processes so fast that it is faster than a double click and the button displays again almost instantly. I’d like to delay the button being displayed or clicked on for a few seconds after it has been clicked.

Of course I am open to other suggestions as well.

1 Like

Hhaha, you are clearly not on a slow pleb server like me, wish i had that issue.

I would have the button hide on click, run the server action, on server action success, show the button, this will then wait for the server to complete before it shows again.

OR

button hide on click, run server action, on server action success, notify, on notify show the button.

OR

Use an action scheduler to count 5 seconds and then show the button.

Perhaps
1.disable/ hide the button on click
2. run scheduler to active/ show button after 3-5 seconds

You could also do a spinner “on executing” to show it is happening when disabling

I wouldn’t hide the button but only disable it, like:

<button dmx-on:click="flow1.run()" dmx-bind:disabled="flow1.executing">
  Run
</button>

If the flow is to fast, you could just add a wait step at the end and let it wait for 3-5 seconds, this way the flow can not be run again in that time period and the button stays disabled.

4 Likes

I am having troubles creating my first flow. It should insert a record then refresh the data and then wait 5 seconds. When I click on the button, nothing happens.

Flow:

<script is="dmx-flow" id="flowCheckIn" type="text/dmx-flow">[
  {
    serverConnect: {
      url: "dmxConnect/api/clients/forms/addclientvisit.php",
      name: "scAddCheckIn"
    }
  },
  {
    serverConnect: {
      url: "dmxConnect/api/clients/lists/clientvisits.php",
      name: "scRefreshCheckIns"
    }
  },
  {
    wait: {delay: 5000}
  }
]</script>

Button:

<button class="btn btn-success btn-sm btn-block" dmx-bind:disabled="flowCheckIn.executing" dmx-on:click="flowCheckIn.run()"><i class="fa fa-road"></i>&nbsp; Check-In Client</button>

I’m sure it’s something I am doing wrong.

Are there errors in the dev tools console?

No, no errors.

So both server actions run properly? I see they are called.

Yes, seems it is inserting but inserting null values, not picking up the form data to insert.

You seem to be calling the server action directly rather than calling a form.submit()

1 Like

Hmmm, how do I call. the form submit?

You are probably right.

You were correct! It now works to submit the form and refresh the data correctly.

Next issue … I need to set a ‘wait’ at the end. I have one set up but it doesn’t seem to be delaying. What value do I put in the delay for say 5 seconds?

never used that but i am guessing in milliseconds

1 Like

Yes, it is milliseconds and seems to be working now. Button doesn’t show the disabled state while flow is executing but it at least works now.

Thanks @Teodor, @Hyperbytes and @patrick

I think Patrick just provided a wrong code. It is flowName.running - just make sure to select it using the UI, it will create the right code for you Brad :slight_smile:

1 Like

Unfortunately it is not selectable in the UI.

I made my first successful flow! :beers:

That fixed it, it is working perfectly now. But the code does have to be added manually. Should I open a bug report?

What do you mean? The running option is available in the UI under the Flow. Just tested this once again.

There is nothing to select there?

Strange, where is the flow located on the page? Is it nested in some container ornis it directly in the body tag?