Can you stop a dynamically checked checkbox resetting on form reset?

Hi,

It may sound strange, but on form reset i want it to revert back to its original state, which was pre-populated with data from a DB query.

The other fields in the form (name, dates etc) all reset back to the value from the SC query that i have set with ‘Dynamic Attribute > Value’ but the checkbox which is set with ‘Dynamic Attribute > Checked’ resets to empty when i use the form reset button.

The value in the query does not change on form reset, just the population of checkbox. Is there something i can do to stop this?

I have tried reloading the SC action/query after form reset using ‘on-click’ rather than a ‘reset’ button type, but this hasn’t worked.

Any input appreciated.

Cheers,
Phil

Hi,
try to use a cookie value and use this value in order to keep the checkbox selected.

Thank you

Ok i’ll look into it. Thanks for quick reply. Guess i better figure out how to use cookies and sessions etc :slight_smile:

So this didn’t work (I used session storage but i can’t imagine it would be any different).

The variable in session storage remained with the same value, but using form reset still unchecked the checkbox regardless of what value the dynamic attribute for checked was returning.

Are there any other suggestions for this?

Yes I had the same issue recently with a form inside of a modal. The quickest way I fixed this was to reload the page on the sever action success. Not ideal but did the job for me.

Thanks max… i could see how that would work, but as you suggested, its not an ideal solution.

Perhaps we could see if team Wappler could weigh in as i’m sure there would be a solution in Wappler… or maybe some custom JS?

So you have a single static checkbox and you are checking it based on some data returned from a server action, Is that right?

Yes, i guess it’s a static checkbox (i.e. its not part of a repeat)

Yes, It is either checked or not checked based on the results of a DB query (a boolean result. in this case either a status of ‘active’ or ‘inactive’.

Like this:

The other fields in the form are populated dynamically by the exact same DB query, and when you reset the form the keep what ever data is coming from the query, its just the checkbox that reverts to unchecked regardless of what is in the DB query.

I tested this locally and see what you mean.
We will try to improve this in the next update(s).

Ok thanks. For what it’s worth it was the same in my old php project.