How to?: Avoid "Unable to parse..." with Plugin mklauber/math.js (<calc>)

57 views
Skip to first unread message

Surya

unread,
Dec 20, 2018, 3:06:07 PM12/20/18
to TiddlyWiki
Hi,

I made some calculation-tiddlers with the plugin

$:/plugins/mklauber/math.js


Everything is fine. The only thing I would like to avoid, is:
When the field "myvalue" of the tiddler "calc Tiddler Data 1" from <$edit-text tiddler='calc Tiddler Data 1' field='gramvalue' size=5/>
is empty, than the calculation shows as result: Unable to parse 'round( * ,2)'

Is it possible (and how?) to avoid that "Unable to parse..."? Maybe, that it shows just nothing or only a / as a result?

The whole is written like this:
<$edit-text tiddler='calc Tiddler Data 1' field='gramvalue' size=5/>g &nbsp;&nbsp;&nbsp;<$edit-text tiddler='calc Tiddler Data 1' field='ingredient' size=20 placeholder="Ingredient"/>&nbsp;&nbsp;&nbsp;<$edit-text tiddler='calc Tiddler Data 1' field='melttemperature' size=4/>°C &nbsp;&nbsp;&nbsp;>>Total-melttemperature of that ingredient in the recipe: ''<$calc>round({{calc Tiddler Data 1!!gramvalue}} * {{calc Tiddler Data 1!!melttemperature}},2)</$calc>°C''

Would be so nice.... :-)
Thanks, Surya!

TonyM

unread,
Dec 20, 2018, 8:27:05 PM12/20/18
to TiddlyWiki
Surya,

Perhaps don't calc unless the required fields have a value

<$list filter="[all[current]has[gramvalue]]">
  Do the calc here because gramvalue will be non zero.
</$list>

Note: has[fieldname] only returns if exist and non blank, has:field[fielname] also returns if exists exist, blank and non blank.

Regards
tony

Surya

unread,
Dec 22, 2018, 11:15:44 AM12/22/18
to TiddlyWiki
Yeah Tony,
that's it!
Thanks to you!
Reply all
Reply to author
Forward
0 new messages