Update text field using the checkbox widget

91 views
Skip to first unread message

kebi

unread,
Dec 8, 2020, 3:10:36 AM12/8/20
to TiddlyWiki
Hello everyone,
I have a tiddler where I display all the tiddlers that contain the word "TODO " in their text field with a checkbox button.
When I click the checkbox button the text field of the corresponding tiddler should change and include the "~~" symbols as prefix and suffix.

I have accomplished this with the following code:

\define line-through()
<$action-setfield text="~~$(text-field)$~~"/>
\end

<$list filter="[regexp:text[^TODO ]]">
<$set name="text-field" value={{!!text}}>
<$checkbox checkactions=<<line-through>> >
{{!!text}}
</$checkbox>
</$set>
</$list>

But I have problems with removing the "~~" prefix and suffix when unchecking the checkbox.
Does anybody know what's the best way to do this?

Mohammad

unread,
Dec 8, 2020, 3:41:43 AM12/8/20
to TiddlyWiki
Kebi,
Why don't use style at display time? Why do you add them to text field?
I believe you should separate these two content from style.

By the way the removesuffix/removeprefixx filter operators shall do what you want

BurningTreeC

unread,
Dec 8, 2020, 4:47:19 AM12/8/20
to TiddlyWiki
Hi @kebi,

for the uncheckactions you could use something like:

\define uncheckactions()
<$set name="splitregexp" value="[\^~~][~~$]">
<$action-setfield text={{{ [[$(text-field)$]splitregexp<splitregexp>] }}}/>
</$set>
\end

BurningTreeC

unread,
Dec 8, 2020, 5:01:02 AM12/8/20
to TiddlyWiki
No, that doesn't work, sorry for my premature proposal

With the current prerelease you could do:

<$set name="splitregexp" value="[\^~~][~~$]">
<$action-setfield text={{{ [[$(text-field)$]search-replace:g:regexp<splitregexp>,[]] }}}/>
</$set>

BurningTreeC

unread,
Dec 8, 2020, 5:15:10 AM12/8/20
to TiddlyWiki
This could work:

\define line-through()
    <$action-setfield text="~~$(text-field)$~~"/>
\end
\define uncheckactions()
<$set name="splitregexp" value="[\^~~][~~$]">
<$set name="splittext" value={{{ [[$(text-field)$]search-replace:g:regexp<splitregexp>,[]] }}}>
<$action-setfield text=<<splittext>>/>
</$set>
</$set>
\end

<$list filter="[regexp:text[^TODO |^~~TODO ]]">

    <$set name="text-field" value={{!!text}}>
        <$checkbox field="text" checked={{{ [<currentTiddler>get[text]prefix[~~]] }}} unchecked={{{ [<currentTiddler>get[text]!prefix[~~]] }}}  checkactions=<<line-through>> uncheckactions=<<uncheckactions>>>
            {{!!text}}
        </$checkbox>
    </$set>
</$list>

kebi

unread,
Dec 8, 2020, 7:31:32 AM12/8/20
to TiddlyWiki
Why don't use style at display time? Why do you add them to text field?

Thank you @Mohammad, I forgot to say that I need to change the value of the tiddler and not only its appearance.

Thank you @BurningTreeC, your solutions works within the current prerelease!


Reply all
Reply to author
Forward
0 new messages