To Do List with Individual Checkboxes

Hi TB Community,

Is there a way to create a To-Do List - Using the repeat function -- with each line item having it's own "checkbox" to mark that specific item as done?

I am hoping to read from a table where task "Description" <> "" (is not blank) and another column (such as) "Completed" or "Status" is blank

I'm familiar with automatically creating tables using the repeat function- shown below- so basically just wondering if there is a way to insert a button to each row within the automatically generated table - to be able to mark that line item as completed or done?

Thank you again!

{dbselect: SELECT Description, Category, Status, Boolean FROM Tasks WHERE Description <> "" AND Completed = ""; space=7ryE3dzqvjpEf34O3XWn2u; menu=no; name=taskstable; multiple=yes}

description category status boolean
{repeat: for row in taskstable}{=row.description} {=row.category} {=row.status} {=row.boolean}{endrepeat}

Here is a small example with utilizing run command to set initial value. There is no dbselect used here, but result of dbselect command follows same structure - list of keyed lists. If checkbox values are required for later use, then repeat locals can be used.

{list=[["enabled": no], ["enabled": yes], ["enabled": no]]}
{repeat: for x in list}{run: enabled=x.enabled}{formtoggle: default=yes; name=enabled}{endformtoggle}
{endrepeat}

1 Like

Hi Mansur - Thank you for creating this!

I took some of your code and also consulted the documentation available for code blocks and came up with this -- the interface is what I want it to look like -- the only thing I am trying to figure out now is how to also have the button insert "Done" or anything into the "Completed" column for the corresponding row/task -- I tried just manually inserting a DB UPDATE command, but it's giving me this error: "Error with the button code. Error in command {dbupdate}: Cannot run dbupdate without instant=yes in a code block"

Here is the snippet that I am working with:

Task List:
{dbselect: SELECT Description, Category, Completed FROM Tasks WHERE Description <> "" AND Completed = ""; space=7ryE3dzqvjpEf34O3XWn2u; menu=no; name=taskslist; multiple=yes}

description category completed
{repeat: for row in taskslist}{=row.description} {=row.category} {=row.completed}
{button: instant=yes
var index = location(taskslist, row)
taskslist = merge(slice(taskslist, 1, index - 1), slice(taskslist, index + 1))
{dbupdate: UPDATE Tasks SET Completed=@doneinsert WHERE retrying.Description <> ""; space=7ryE3dzqvjpEf34O3XWn2u; autoaddfields=yes}
; label={{^^%F0%9F%97%91%EF%B8%8F^^}}}{endrepeat}

instant is a setting on dbupdate command. I updated your snippet to have it specified there. Note it will trigger each time you click the button.

Task List:
{dbselect: SELECT Description, Category, Completed FROM Tasks WHERE Description <> "" AND Completed = ""; space=7ryE3dzqvjpEf34O3XWn2u; menu=no; name=taskslist; multiple=yes}

description category completed
{repeat: for row in taskslist}{=row.description} {=row.category} {=row.completed}
{button: var index = location(taskslist, row)
taskslist = merge(slice(taskslist, 1, index - 1), slice(taskslist, index + 1))
{dbupdate: UPDATE Tasks SET Completed=@doneinsert WHERE retrying.Description <> ""; space=7ryE3dzqvjpEf34O3XWn2u; autoaddfields=yes; instant=yes}
; label={{^^%F0%9F%97%91%EF%B8%8F^^}}}{endrepeat}

1 Like

Thank you! That got rid of that error- What would be the correct way to specify which row to update within the DB update (correlating to the same line item/task it is showing up with?) Basically it's telling me that I'm not specifying a row to update, typically that's an easy fix but I'm not sure how its affected within the repeat function

Thank you

And/or --- what if I were to use a simple dropdown - to mark the status of the task- what would be the right way to structure a DBUPDATE command to correlate with the same task within the repeat function?

Thank you

Task List:
{dbselect: SELECT Description, Category, Completed, rowid() AS `Row ID` FROM Tasks WHERE Description <> "" AND Completed = ""; space=7ryE3dzqvjpEf34O3XWn2u; menu=no; name=taskslist; multiple=yes}

description category completed
{repeat: for row in taskslist}{=row.description} {=row.category} {formmenu: default=; Completed; Need Help; name=taskstatus}{if: taskstatus="Completed"}{dbupdate: UPDATE Tasks SET Completed="Done" WHERE rowid()=@row.row; space=7ryE3dzqvjpEf34O3XWn2u}{endif}{endrepeat}

You can utilize rowid function that returns unique id for a row. Once you obtain it through dbselect, it can be used to dbupdate that particular row through comparing it with the id you have. I've created bundle to demonstrate that. You might need to copy the bundle to see it in the action.

{run: tasks={dbselect: SELECT Name, Completed, rowid() as row_id FROM Table1; space=id; menu=no; multiple=yes}}
{repeat: for (task, i) in tasks}{=task.name} {row_id=task.row_id}{if: not task.completed}{button: {dbupdate: UPDATE Table1 SET Completed=yes Where rowid()=@row_id; space=id; instant=yes}
tasks=merge(slice(tasks,1,i-1), [["name": task.name, "row_id": row_id, "completed": yes]], slice(tasks,i+1,count(tasks)))
; label="Mark done"}{else}Done{endif}
{endrepeat}

1 Like

Thank you Mansur!