I'm trying to create a button which creates a new tiddler with a field value one larger than the previous max value in that field. I'm using the mathjs plugin and also plan to use the domtext macro to feed the value into the sendmessage widget call.
My code is using the element hierarchy p->$list->$calc. The 'p' is there so I can eventually use the domtext macro.
But I'm not there yet because when I click my button, I get this error:
Uncaught NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
Here is my code:
<!-- display the matching tiddlers -->
<$list filter="[has[binindex]!nsort[binindex]limit[10]]"/>
<!-- Find the lowest unused binindex value greater than or equal to zero -->
<p id="nextindex" style="display:inline;">
<$list filter="[has[binindex]!nsort[binindex]limit[1]]" emptyMessage="0">
<$calc>{{!!binindex}}+1</$calc>
<!-- Create new tiddler. Eventually will use the domtext macro to set the binindex from above calculation. For now just a hard-coded value -->
<$action-sendmessage $message="tm-new-tiddler" binindex="15" text="test"/>
I looked into it a little and couldn't tell if the listwidget is at fault for passing a wrong nextSibling to the calc widget or if the calc widget somehow did something wrong to cause the listwidget to calculate a wrong nextSibling. Anyone have any ideas?
As a workaround, I tried to replace the listwidget with a set widget. This prevented the error, but now I'm having a refresh issue. Every time I click the 'new' button, the same value is reused for binindex until I force the entire tiddler containing this code to be refreshed by closing and reopening.
<!-- display the matching tiddlers -->
<$list filter="0 [get[binindex]] +[!nsort[]limit[10]]"/>
<!-- Find the lowest unused binindex value greater than zero -->
<p id="nextindex" style="display:inline;">
<$set filter="0 [get[binindex]] +[!nsort[]limit[1]]" name="maxindex">
<$calc><<maxindex>>+1</$calc>
<!-- Create new tiddler -->
<$action-sendmessage $message="tm-new-tiddler" binindex=<<domtext nextindex>> text="test"/>
Paste the above code into a new tiddler at
http://tobibeer.github.io/tw5-plugins and click the new button multiple times. The $list widget at the top of the tiddler changes each time I hit the 'new' button, but $calc value doesn't change until I close and re-open the tiddler. And since the $calc value didn't change, each new tiddler gets the same binindex value.
Brian