I have checkboxes and I am trying to get them to automatically load as being “checked” based on whether they exist in a database query. I have it working when I have the [0] in the query result but only for the first one, obviously. But I am trying to have it so all checkboxes are checked if they exist in the result.
So here is what I am trying to achieve. I run a server connect action that searches “mymodules”. If a name exists in this query that matches the value of the checkbox, then make the checkbox checked. If it doesn’t exist, then uncheck.
Is there a simple way this can work?
This is what I have in my “checked” condition… but it only checks the first box
That complicates things!
I was going to suggest a right join to the options in your subquery to return an array of all options with those selected checked but that puts and end to that idea
mmm I thought so! So the idea is that my other app has a list of modules (moduleName), and this app searches these available modules, then populates the checkbox. When I click a checkbox, it adds that value to the database as an available module).
Should be simple this though… it’s really just checking if a particular module exists in my db (via moduleName), and if it matches the checkbox value (which means it exists in the db) then have it checked. If it doesn’t exist in db then uncheck.
I am 11000 miles away from my office but there is probably a way to do this with server connect data management by manipulating arrays but without access the wappler I can’t really assist more, sorry
So you have a query that returns [1, null, 1, 1, 1, null, null, 1]?
(Where 1=exists and null=not exist)
Something like that?
if yes, you just set a condition in your checkbox value that checks if the value coming from the query is 1 or null and if it is null set it to 0. Something like that: query.value==1?1 :0
I have understood that you need to show the values to your page… Not updating in your server action…
If you talk about updating please let us know.
Query returns multiple “moduleNames”, which dynamically populates my checkbox names
When I click on a checkbox, I have a SC action that saves the name of that module in the DB.
This is where I am stuck - I need the checkbox to be ticked/checked on page load if that value exists in the database and it matches the corresponding checkbox name. Where I am stuck is because the DB query is for multiple records, it gives me the following: searchmymodules.data.query[0].moduleName which allows my first checkbox to be ticked. I tried replacing [0] with [$index] but still no luck