Hi,
I have list with packing items and want to create an action, that lists all items with a battery symbol as buttons and then, once I press a button replaces it with a charger.
This is a sample list:
Title
[ ] hallo
[ ] ade
[ ] one
[ ] twoπ
[ ] three
[ ] four
And this is the action I have. It lists the items with a battery correctly but it does not replace the battery symbol. What am I doing wrong?
Code:
let prompt = Prompt.create();
prompt.title = βChargeβ;
Have you tried it with something more basic than the battery and charger symbols? I would suspect (only a guess) they could be problematic.
I am, by the way, intrigued at the idea of tagging items with symbols like these. (Tagging deeper than the normal Drafts tags - which work at the draft level.)
//Specify some standard strings
const UNCHECKED = "- [ ] ";
const UNCHARGED = "π";
const CHARGED = "π";
//Set-up the prompt
let prompt = Prompt.create();
prompt.title = "Charge";
//Build the list of devices requring charging
let packingList = draft.content.split("\n").forEach(function(item)
{
if (item.includes(UNCHECKED) && item.includes(UNCHARGED))
{
prompt.addButton(item.replace(UNCHECKED, "").replace(UNCHARGED, ""));
}
});
//Show the prompt
prompt.show();
if (prompt.buttonPressed)
{
//Prompt was shown, update draft content
draft.content = draft.content.replace(UNCHECKED + prompt.buttonPressed + UNCHARGED, UNCHECKED + prompt.buttonPressed + CHARGED);
draft.update();
}
Based on testing with a draft like this:
# Title
- [ ] halloπ
- [ ] ade
- [ ] oneπ
- [ ] twoπ
- [ ] three
- [ ] four π
Tip:
Please also do use triple back ticks to code block your draft and your code. The forum software will interpret Markdown content, and also apply things like smart quotes to code. This means that to even start helping, we have to try and reverse what the forum applies to your original entries.
Hi @sylumer and thanks for your help. Unfortunately it doesnβt work here either. What might I be missing or doing wrong, I understand the code worked with your list?