[tw5] SetField Widget and radiobuttons? @matabele

200 views
Skip to first unread message

Måns

unread,
Jun 19, 2014, 7:00:07 PM6/19/14
to tiddl...@googlegroups.com
Hi Matabele


Does  Setfield widget work with radiobuttons?

I tried this to no avail:

<$setfield set="!!gender2c" setTo="Han">
<$setfield set="!!gender2" setTo="han">
<$setfield set="!!genderc" setTo="Ham">
<$radio field="gender" value="ham"> dreng</$radio>
</$setfield></$setfield></$setfield>

<$setfield set="!!gender2c" setTo="Hun">
<$setfield set="!!gender2" setTo="hun">
<$setfield set="!!genderc" setTo="Hendes">
<$radio field="gender" value="hende"> pige</$radio>
</$setfield></$setfield></$setfield>

I think it would be very nice if the widget did work with radio buttons and even checkmarks.

Cheers Måns Mårtensson

David Gifford

unread,
Jun 19, 2014, 10:15:41 PM6/19/14
to tiddl...@googlegroups.com
haha sorry, couldn't resist mentioning that I thought for a moment that you wrote "Seinfeld widget".  :-) Is probably a widget that fixes everything by throwing a Junior Mint into TiddlyWiki (https://www.youtube.com/watch?v=M29A6rZpKqk)

Dave

Matabele

unread,
Jun 20, 2014, 1:20:00 AM6/20/14
to tiddl...@googlegroups.com
Hi Mans

No -- the <$setfield> widget responds to a widget message -- this would require a new radio type widget which sends a widget message when the button is clicked.

I presume your intention is to set the value of several fields to a value upon checking a radio button?

I did play around with a checkbox type widget which sets the value of a field when clicked -- I was busy trying to get it to toggle a field between two values, that is, send different widget messages when checked and unchecked. 

I'll have another look at it  -- and, perhaps, rename it the <$einfeld> widget :-)

regards

Matabele

unread,
Jun 20, 2014, 7:57:09 AM6/20/14
to tiddl...@googlegroups.com
Hi Mans

The radio 'button' reports on the value of a field -- it is checked if the value matches and unchecked if it does not. This behaviour is not compatible with a radio 'button' that sets the value of multiple fields.

I'm not sure what the best avenue is to take with this king of use case -- my current idea is to create a widget that sends one widget message upon being checked and another upon being unchecked. This would allow several fields to be toggled between two values using two stacks of <$setfield> widgets around a button. 

I think the usage I had in mind differed -- this was to list a number of tiddlers according to some filter expression, then toggle the value of a field between two values for all tiddlers in the list.

I don't know if either of these tactics (or some other tactic) is best suited to your needs.

regards 

On Friday, June 20, 2014 1:00:07 AM UTC+2, Måns wrote:

Måns

unread,
Jun 20, 2014, 12:51:51 PM6/20/14
to tiddl...@googlegroups.com
Hi Matabele

My actual usecase is that I use two radio 'buttons' to toggle the value of one field 'gender' between "him" or "her" 

Because I need different variations on "him" or "her" I need to be able to more fields at once - with different versions - eg. "Him", "he", "He" and "her", "Her", "she", "She" etc...

This way I can use eg.: {{!!gender}}, {{!!gender2}}, {{!!gender3}} in my text templates.

Imo - it seems to be an 'overkill' if you have to set all variations with a radio button for each individual variation every time you use the template...

Maybe there's a better way to control this via some kind of aliassing  - don't know...?

Cheers Måns Mårtensson

Matabele

unread,
Jun 20, 2014, 1:34:45 PM6/20/14
to tiddl...@googlegroups.com
Hi Mans

The variations of gender could be looked up in two data tables 'male' and 'female', in such a way that:

male##gender1 --> him
female##gender1 --> her
male##gender2 --> Him
female##gender2 --> Her 
...
and so on

Then the only variable that needs to be set for each person is male/female -- all variations of gender are text-reference lookups using either 'male' or 'female' (the titles of the two data tables) as the only variable

regards

Måns

unread,
Jun 20, 2014, 2:28:40 PM6/20/14
to tiddl...@googlegroups.com
Hi Matabele

 
The variations of gender could be looked up in two data tables 'male' and 'female', in such a way that:

male##gender1 --> him
female##gender1 --> her
male##gender2 --> Him
female##gender2 --> Her 

 
all variations of gender are text-reference lookups using either 'male' or 'female' (the titles of the two data tables) as the only variable

I think I understand what you are saying - however I don't have a clue how I should set it up... 

Could you perhaps write a small example - in a TW5 - or point to a similar practical example which might give me an idea how to implement it myself?  

Cheers Måns Mårtensson

Matabele

unread,
Jun 20, 2014, 4:39:56 PM6/20/14
to tiddl...@googlegroups.com
Hi Mans

1. create a new tiddler and name this 'male'
2. create a new tiddler and name this 'female'
3. set the type of both of these tiddlers to 'data dictionary'
4. in the text field of 'male' make entries like:
gender1:him
gender2:Him
gender3:Mr
... and so on
5. in the text field of 'female' make entries like:
gender1:her
gender2:Her
gender3:Mrs
... and so on
6. when you want 'him' -- you can use the text reference {{male##gender1}} ... and so on
7. when you want 'her' -- you can use the text reference {{female##gender1}} ... and so on

I think in your use case you would want a variable as the name of the data tiddler -- so references might look something like {{$gender$##gender1}}, where the variable takes the value 'male' or 'female' as appropriate. I think you'll need a macro call to insert the variable before using the text-reference as the syntax I've used above won't work (this was for illustration only.)

regards

Måns

unread,
Jun 20, 2014, 5:05:43 PM6/20/14
to tiddl...@googlegroups.com
Hi Matabele

Thank you very much!!!
Yet another mystery has been solved :-)

To me it seems as if the syntax for retrieving "slices" uses the old syntax for retrieving "sections" (TWc lingo) in TW5...

Cheers Måns Mårtensson

Alberto Molina

unread,
Jun 21, 2014, 11:26:48 AM6/21/14
to tiddl...@googlegroups.com
Hi Mans

1. create a new tiddler and name this 'male'
2. create a new tiddler and name this 'female'
3. set the type of both of these tiddlers to 'data dictionary'
4. in the text field of 'male' make entries like:
gender1:him
gender2:Him
gender3:Mr
... and so on
5. in the text field of 'female' make entries like:
gender1:her
gender2:Her 
gender3:Mrs
... and so on
6. when you want 'him' -- you can use the text reference {{male##gender1}} ... and so on
7. when you want 'her' -- you can use the text reference {{female##gender1}} ... and so on

I think in your use case you would want a variable as the name of the data tiddler -- so references might look something like {{$gender$##gender1}}, where the variable takes the value 'male' or 'female' as appropriate. I think you'll need a macro call to insert the variable before using the text-reference as the syntax I've used above won't work (this was for illustration only.)


Very interesting! Thanks!

Alberto 

Måns

unread,
Jun 23, 2014, 9:29:38 AM6/23/14
to tiddl...@googlegroups.com
Hi Matabele

 
I think in your use case you would want a variable as the name of the data tiddler -- so references might look something like {{$gender$##gender1}}, where the variable takes the value 'male' or 'female' as appropriate. I think you'll need a macro call to insert the variable before using the text-reference as the syntax I've used above won't work (this was for illustration only.)

You are absolutely right :-)

I set gender as a field "gender" to male or female - now I need to retrieve the result from the correct library..

I tried to do it like this: {{!!gender##gender2b}} 

It doesn't seem to be possible to use templates with substitutions as values either

Sth. like:

index1:Value of {{!!gender##gender2b}} should be Him

Simply:

index2:{{!!title}}

Doesn't show the title when you input it as {{IndexTiddler##index2}}

Does anyone know how to exploit a datalibrary as a library of textsnippets with substitution markers? 

Cheers Måns Mårtensson

Matabele

unread,
Jun 23, 2014, 10:00:12 AM6/23/14
to tiddl...@googlegroups.com
Hi Mans

Use a macrocall:

\define getGender(gender,type)
{{$gender$##$type$}}
\end

<<getGender {{!!gender}} {{!!type}}>>



if this doesn't work -- try set widgets:

\define getGender()
{{$(gender)$##$(type)$}}
\end

<$set name="gender" value={{!!gender}}>
<$set name="type" value={{!!type}}>
<<getGender>>
</$set></$set>

regards
Reply all
Reply to author
Forward
0 new messages