mathjs insertBefore error when using list widget

59 views
Skip to first unread message

Brian Theado

unread,
Dec 5, 2015, 3:10:06 PM12/5/15
to tiddl...@googlegroups.com
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>
  </$list>
</p>

<!-- Create new tiddler. Eventually will use the domtext macro to set the binindex from above calculation. For now just a hard-coded value -->
<$button>
  <$action-sendmessage $message="tm-new-tiddler"  binindex="15" text="test"/>
  New
</$button>

Paste this code into a new tiddler at http://mklauber.github.io/tiddly-mathjs/latest.html and click the "New" button and the above error should result.

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>
  </$set>
</p>

<!-- Create new tiddler -->
<$button>
  <$action-sendmessage $message="tm-new-tiddler"  binindex=<<domtext nextindex>> text="test"/>
  New
</$button>

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

Brian Theado

unread,
Dec 5, 2015, 8:52:41 PM12/5/15
to tiddl...@googlegroups.com
I looked more into this and think it is an issue with the mathjs calc
widget. I have opened an issue at
https://github.com/mklauber/tiddly-mathjs/issues/5 and described the
small calc widget fix which solves the issue for me.

Tobias Beer

unread,
Dec 6, 2015, 7:12:21 PM12/6/15
to TiddlyWiki
Hi Brian,

Perhaps you are interested in the new eval plugin:


Best wishes,

Tobias. 

Brian Theado

unread,
Dec 6, 2015, 8:55:08 PM12/6/15
to tiddl...@googlegroups.com
Tobias,

On Sun, Dec 6, 2015 at 7:12 PM, Tobias Beer <beert...@gmail.com> wrote:
> Perhaps you are interested in the new eval plugin:
>
> https://groups.google.com/forum/?fromgroups=#!topic/tiddlywiki/KI0zBADe4rA

Excellent! I like this much better than the domtext approach. Looks
like the eval plugin is packed with features. I only needed the most
basic functionality to replace the code I previously posted:

<!-- Using list widget instead of set variable widget because set
doesn't refresh the way I want -->
<$list filter="[get[binindex]!nsort[]limit[1]eval[title+1]]">
<$button>
<$action-sendmessage $message="tm-new-tiddler"
binindex={{!!title}} text="test"/>
New
</$button>
</$list>

Much cleaner now. Thanks a bunch for the plugin!

Brian
Reply all
Reply to author
Forward
0 new messages