AC2 - Using dynamic events (checked/unchecked) and data binding - how to, AC1 worked fine

Hi all,

This is my setup:

  • I have a toggle, the value of the toggle is determined by an integer field from the database (0/1).
  • I then have dynamic events triggered by the toggle when the user takes action (e.g. checks it or unchecks it) which triggers an API call to update the database and on:success I refresh the pages data.

On AC1 - this works perfectly and as expected. The value of the data is shown in the toggle (on/off) based on data from the DB. When the user checks/unchecks it then updates.

On AC2 on page load it triggers the update. I’m assuming due to the data binding being different to AC1 and so the dynamic events believe they are being triggered however it’s just the data binding action in AC2.

It’s undesirable for the api on the page to trigger on page load so I’m wondering if anyone has experienced this, and can provide any suggestions to solve it.

I think you should in your toggle update event, add a condition to check if the api that reads the data (0 or 1) for this toggle has been executed successfully (has values)… Then update the toggle and do what you have to do.
So, I would use a simple inline condition in your toggle update like this:
serverAction ? (update) : (nothing to do)

Can you post the code of the toggle here?

I actually did try using flows with conditions to check for data/matching data but none impacted the issue I’m finding myself with unfortunately. I could try inline but suspect it’ll be the same outcome.

Better post the code my friend to see… I’m curious to see

I suppose this Patrick’s comment is related…

Thanks Teo. Please note that the difference between checked/unchecked with one using ‘flows’ is due to recent testing/trying to find a solution.

<div class="form-check form-switch">
                                                <input class="form-check-input" type="checkbox" id="profile_visible_switch" name="profile_visible_switch" dmx-on:checked="visibility_search.load({visibility: 1})" dmx-bind:checked="profile_data.data.query[0].visible_to_employers==1" dmx-on:unchecked="run({run:{outputType:'text',action:`visibility_search.load({visibility: 0})`}})" dmx-class:checkgreen="checked">
                                                <label class="form-check-label text-nowrap" for="profile_visible_switch">Let companies find me&nbsp;&nbsp;<i class="fas fa-info-circle" dmx-bs-tooltip="'Turning this on will let companies find and message you regarding opportunities. Any companies you have hidden will not be able to see your profile.'" data-bs-trigger="hover"></i></label>
                                            </div>

I’ve posted an update in the other topic that fixes an issue with checkbox not updating.

Hi @patrick - the latest update still has not resolved this issue.

Fixed in Wappler 6.4.2

This topic was automatically closed after 43 hours. New replies are no longer allowed.