On Saturday, August 24, 2019 at 8:04:37 AM UTC-7, vpl wrote:
>
> I've created a basic javascript  macro that look for a field ('categfield') 
> from a tiddler ('Test-tiddler')
> This macro is called from the 'Test-tiddler'  that allows setting the 
> 'categfield" with a $select
> Here is the 'Test-tiddler'
> By Category:
> <$select field="categfield">
> <option value="Categ-1">Categ-1</option>
> <option value="Categ-2">Categ-2</option>
> <option value="Categ-3">Categ-3</option>
> </$select>
> <<testmacro>>
> When I open 'Test-tiddler' and select a categfield the console.log in the 
> testmacro.js displays correctly the categfield value. Fine
> Now if I create a 'test-tab' tiddler like
> <<tabs "Tab1 Test-tiddler "Tab1" "$:/state/tab1" "tc-vertical">>
> And access the ''Test-tiddler' from there,* the categfield are not update 
> when I change it from the select !!*
>

The $select widget operates on the "currentTiddler" unless you specify the 
target tiddler (i.e., using tiddler="..." as a param).

Thus, your initial test works, because the $select widget and the 
<<testmacro>> invocation are both in the same tiddler, "Test-tiddler", 
which you are viewing directly.

However...

When a tiddler is shown via the tabs macro, the <<currentTiddler>> is the 
tiddler *in which the tabs macro occurs* (i.e., "test-tab").

Thus, your second test fails, because the $select widget is saving it's 
value into "test-tab", rather than "Test-tiddler".

To use $select correctly, you can explictly specify the target tiddler 
using <$select ... tiddler="Test-tiddler">.

Of course, this is probably not very useful, as the target is hard-coded, 
and I suspect you're end-goal is to be able to save the selected value in 
the currentTiddler, regardless of what tiddler that is.

Fortunately, there is a much more flexible way to solve the problem:

The <<tabs>> macro sets another "core" variable: <<currentTab>>, which is 
available *within each tab* that is shown.

To make your content use that target instead of the <<currentTiddler>> you 
can wrap it within a $tiddler widget, like this:

<$tiddler tiddler=<<currentTab>>>

By Category:
<$select field="categfield">
<option value="Categ-1">Categ-1</option>
<option value="Categ-2">Categ-2</option>
<option value="Categ-3">Categ-3</option>
</$select>
<<testmacro>>

</$tiddler>

When the above is viewed *directly*, the value of <<currentTab>> is 
undefined, and the $select operates on <<currentTiddler>>, just as your 
initial test does.

When viewed via a <<tabs>> macro, the value of <<currentTab>> *is* defined 
and the <<currentTiddler>> is then set by the $tiddler widget to match, so 
that the $select will still operate on the desired tiddler.

I hope this explanation isn't too confusing...

enjoy,
-e
Eric Shulman
TiddlyTools: "Small Tools for Big Ideas!" (tm) http://tiddlytools.github.io 
(TWClassic)
InsideTiddlyWiki: The Missing Manuals



-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/ad23a311-0d2b-407d-9307-a5d78c622427%40googlegroups.com.

Reply via email to