@Mohammad yes the toggle operator is best used with list fields.

You can further simplify and skip the list widget:

<$vars
   lightPalette="$:/palettes/Vanilla"
   darkPalette="$:/palettes/SolarFlare"
>
<$button>Day/Night II
<$action-setfield $tiddler="$:/palette" 
text={{{[{$:/palette}match<lightPalette>then<darkPalette>else<lightPalette>]}}}/>
</$button>
</$vars>

On Tuesday, December 15, 2020 at 9:59:11 AM UTC+1 Mohammad wrote:

> It seems in this case there are other simple solutions too, while in my 
> opinion toggle is the most semantic one but in its current implementation 
> is tricky to use for toggling a field can be changed outside the script.
>
> These are other solutions that do not use toggle but very simple.  Of 
> course simple is the best but not simpler.
>
> *!! Simple solution*
>
> <$button>Day/Night
> <$list 
> filter="[{$:/palette}match[$:/palettes/Vanilla]then[$:/palettes/SolarFlare]else[$:/palettes/Vanilla]]">
> <$action-setfield $tiddler="$:/palette" text=<<currentTiddler>>/>
> </$list>
> </$button>
>
>
> *!! Good practice*
>
> <$vars 
>    lightPalette="$:/palettes/Vanilla" 
>    darkPalette="$:/palettes/SolarFlare"
> >
> <$button>Day/Night II
> <$list 
> filter="[{$:/palette}match<lightPalette>then<darkPalette>else<lightPalette>]" 
> variable=selectedPalette>
> <$action-setfield $tiddler="$:/palette" text=<<selectedPalette>>/>
> </$list>
> </$button>
> </$vars>
>
>
> You may read *darkPalette *and *lightPalete *from a config tiddler fields.
>
> Best wishes
> Mohammad
>
>
> On Mon, Dec 14, 2020 at 4:14 PM Mohammad Rahmani <mohammad...@gmail.com> 
> wrote:
>
>> I use the below button to toggle between day/night palette 
>>
>> <$button>Day/Night
>> <$action-listops $tiddler="$:/palette" $field="text" 
>> $subfilter="+[toggle[$:/palettes/Vanilla],[$:/palettes/SolarFlare]]" />
>> </$button>  
>>
>> The problem here is if $:/palette is not empty and has not one of the two 
>> values above, then I get the wrong values in the text field (actually the 
>> value is appended). How can I replace the field value using toggle operator.
>>
>>
>>
>> Best wishes
>> Mohammad
>>
>

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/ded9b6a8-ce10-44a4-8f2b-15ed3c32480bn%40googlegroups.com.

Reply via email to