Delete Tasks/Checkbox


#1

Is there an action written that deletes all the items in a draft that has an x in the checkbox?


#2

There are a couple of actions which each move all completed tasks, -[x], down to the bottom of the list. It’s then just a matter of going to arrange (hamburger icon at bottom of screen) and then selecting the block of completed tasks, then swiping left to remove them en masse.

Someone may chip in with a more specific, Javascript action, but this set up has worked well for me.

https://actions.getdrafts.com/a/1HP

https://actions.getdrafts.com/a/1Ec


#3

One of these should hopefully suffice as I know some people differ in how they markup their lists.

It should deal with marked last lines (no trailing new line), and whitespace at the start of the line if you have any indented tasks. If you have task markers embedded within a line, rather than at the start, they will be ignored or treated as pat of the first task on the line and could be removed. These actions are very much intended for basic check list use. Please keep that in mind if you use a more sophisticated task set-up in Drafts.

Expand here to see the JavaScript they use
//Uncomment appropriate one:

//For task marker is "- [x]"
let regex = /(\S*)- \[x\](.*)(\n)?/g;

//For task marker is "[x]"
//let regex = /\[x\](.*)(\n)?/g;

draft.content = draft.content.replace(regex, "");
draft.update();

If you have something slightly different, it shouldn’t be too hard to modify the regular expression to accommodate.

Hope that helps.


#4

Here’s how I do it:

draft.content = draft.content.split( /\n/ )
                             .filter( x => !x.match( /^(?:-\s*)?\[x\]/i ) )
                             .join( '\n' )
draft.update()