2 checkboxes as OR choice, like radio buttons

193 views
Skip to first unread message

Dave

unread,
Jun 24, 2018, 11:55:43 PM6/24/18
to TiddlyWiki
I'm trying to make a macro that presents a pair of checkboxes like this: R[[_]] [[_]]L.

I can get the checkboxes to assign 1 for checked and 0 for unchecked, but I'd like to be able to cause the Right checkbox to automatically uncheck when the Left one checks and vice versa.

Here's what I have that's not working:

\define nullr(testname)
<$action-setfield $tiddler=<<currentTiddler>> $field="$testname$.right" $value="0" />
\end
\define nulll(testname)
<$action-setfield $tiddler=<<currentTiddler>> $field="$testname$.left" $value="0" />
\end


\define rorlcheck(testname)
R<$checkbox tiddler="""$(currentTiddler)$""" field="$testname$.right" checked="1" unchecked="0" actions="<<nulll '$testname$'>>" >L<$checkbox tiddler="""$(currentTiddler)$""" field="$testname$.left"  checked="1" unchecked="0" actions="<<nullr '$testname$'>>">
\end

<<rorlcheck test>>


Can anyone tell me how to make this work?

Thank you,
Dave


P.S. I've also tried it with """$(currentTiddler)$""" in the null macros

Mark S.

unread,
Jun 25, 2018, 12:36:52 AM6/25/18
to TiddlyWiki
Can't you just have the two boxes share the same field, but with opposite inputs. e.g.

L <$checkbox field=status checked="L" unchecked="R"/>
R <$checkbox field=status checked="R" unchecked="L"/>

Seems to work (after the first click to set up the field).

-- Mark

TonyM

unread,
Jun 25, 2018, 12:45:57 AM6/25/18
to TiddlyWiki
Dave,

Using a field as the state field, as opposed to the tags allows you to do this for a two value check

<$checkbox field="selected" checked="a" unchecked ="b"> A?</$checkbox>
<$checkbox field="selected" checked="b" unchecked ="a"> B?</$checkbox>

You do not need two values 0 and 1 and 0 and 1 if they are intimately linked  such as "1 and 0" OR "0 and 1"

Or 

<$checkbox field="selected" checked="left" unchecked ="right"> Left?</$checkbox>
<$checkbox field="selected" checked="right" unchecked ="left"> Right?</$checkbox>

this kind of logical selection is is often referred to as "radio buttons".


Also with left and right being the choice you could use the range widget, in this case with a neither left or right https://tiddlywiki.com/#RangeWidget

<$range field="lorr" min="-1" max="1" default="0" increment="1"/> {{!!lorr}}

There are many ways to do this.

Regards
Tony

Dave

unread,
Jun 25, 2018, 1:05:08 AM6/25/18
to TiddlyWiki
Thank you both for that info. The problem is that i need to be able to check one or the other, but also have the option to make neither checked (after having first checked it), so its not exactly like a radio botton.

My main problem seems to be using <<currentTiddler>> somehow in the action part of the checkbox macro ( unless theres a simpler way to get the “half-radio-button” function i described).

TonyM

unread,
Jun 25, 2018, 1:31:31 AM6/25/18
to TiddlyWiki
Dave,

You can have very sophisticated logic behind buttons, using action widgets you can have any combination of fields set for each button press including to unset/reset another field or value that drive another button.

If you can state your required logic a little more clearly, we can give you some options. Personally I cant quite workout the convoluted solution you are having trouble with. Can you use pseudo-code perhaps.?

Regards
Tony

Dave

unread,
Jun 25, 2018, 1:22:45 PM6/25/18
to TiddlyWiki
Thank you.  Here's what I need to happen:

R[[_]] L[[_]]  <-- when you check the left one, it becomes checked, and if checked again it becomes unchecked, same for the right one, and if either one is checked, its opposite becomes unchecked, but having done that, you can uncheck either one (to have neither checked) and in doing so *** the opposite does //not// become checked again***  i.e. a checkbox only becomes checked by the user checking it, not when the user unchecks the other.

in the code in the first post, what I'm trying to do is when a checkbox is checked (putting the value of "1" in the current tiddler's field "test.right" (e.g.)), it also runs the macro "nulll" that assigns "0" to the field "test.left".

My problem is that with the "currentTiddler" reference I can't seem to get that to work.

Mark S.

unread,
Jun 25, 2018, 2:12:41 PM6/25/18
to TiddlyWiki
The logic of the buttons is confusing. What is the use-case?

You want the buttons to swap their status, but only until the 2nd click? What condition returns the buttons to independent operation?

Let's say you click the right button. Then you click the right button AGAIN. Presumably the left button is now clicked. NOW will clicking the left button turn off only the left button, or will it turn on the right?
 
-- Mark

Dave

unread,
Jun 25, 2018, 2:31:12 PM6/25/18
to TiddlyWiki
The use case is something like this:
cranial nerve 12 test: tell the patient to stick out their tongue.  You're looking for either straight ahead (normal) or deviating to the R or to the L.

Lets say initially I marked it as deviating to the R, so I check off the "R" box.  This type of test is either/or or possibly negative (both unchecked) but never both checked.  Lets say I decide, "no, I was hallucinating, I'm going to call that negative (normal)" so I'd want to uncheck the R checkbox, but I don't want the L one to suddenly become checked - I want to call it a normal test (both unchecked)

Does that help clarify?

Dave

unread,
Jun 25, 2018, 2:35:23 PM6/25/18
to TiddlyWiki
But if I decided I was being dyslexic and want to change my mind and say its deviating to the L, checking that would uncheck the R one

@TiddlyTweeter

unread,
Jun 25, 2018, 2:50:17 PM6/25/18
to tiddl...@googlegroups.com
I'm the right patient to ask about this as I have Multiple Sclerosis.

So you do the Medical Tuning Fork test on my Left Ankle. I report a clear NO that I can sense no vibration inside the bone. That is a positive measure. On my Right Elbow I clearly sense the vibration and you, doctor, can see my right hand has grip and normal ability. A positive measure of normal function.

Now, take the case of my Right Ankle. I report that I can feel SOME vibration though you, doctor, can confirm that the Right foot has inclination to Babinski's Reflex. Is it a positive or a negative? It seems IN-BETWEEN.

Is it in-betweens you are trying to get at?

Mark S.

unread,
Jun 25, 2018, 3:07:22 PM6/25/18
to TiddlyWiki
So ... you want to be able to check either box, and automatically CLEAR the other box. And at no point could it be left AND right because then your patient would be speaking with forked tongue.

Right?

From a systems analyst point of view, it should be a 4 way radio button with "unasked (default)" , "Normal", "Left", "Right" . That way you can check your work in case the dyslexic, amnesiac doctor didn't do the test ;-)

-- Mark

@TiddlyTweeter

unread,
Jun 25, 2018, 3:17:41 PM6/25/18
to TiddlyWiki
I don't blame the doctor. They feel bad enough already people die in their care.

Regarding an actual answer. Well its has quite a lot to do with the specific disease/condition/state-of-the doctor.

Surely you need to be able to define easily many "multi-toggle" states? Or picklists of criteria.

Dave

unread,
Jun 25, 2018, 3:48:38 PM6/25/18
to TiddlyWiki
@TiddlyTweeter - yes I will have tests like that, but that's not what I'm getting at here.

Mark -

So ... you want to be able to check either box, and automatically CLEAR the other box. And at no point could it be left AND right because then your patient would be speaking with forked tongue.

Right?

Correct! (and ha ha, good one!)

And yes, later on I was going to add some indication of the test being negative vs untested :) - I just need to get past this roadblock of clearing the other checkbox.  If the checkbox info was being stored at some absolute tiddler somewhere it would be easy, but because the naming is relative to the <<currentTiddler>> $(currentTiddler)$ (??) I can't seem to get it to work right. 

Mark S.

unread,
Jun 25, 2018, 5:45:30 PM6/25/18
to TiddlyWiki
What exactly are you seeing when you do it? For me it seems to be working fine. Click R. Check. Click L. Check and clear R.

Is there any possibility that you're running the code on an older version of TW?

Good luck!
-- Mark

Dave

unread,
Jun 25, 2018, 5:53:15 PM6/25/18
to TiddlyWiki
Oh, I never thought of that - I'm on 5.1.13, and I see the latest is 5.1.17 - I'll give that a try

David Shaw

unread,
Jun 25, 2018, 6:07:50 PM6/25/18
to tiddl...@googlegroups.com
Let me see if I have this straight.

There are two check boxes.
There are three different, legal states

1) Both boxes unselected
2) Box 1 selected, box 2 unselected
3) Box 2 selected, box 1 unselected (the reverse of 1)

If the boxes are in state 1, then clicking on a box puts them in either state 2 or state 3, depending on which box is clicked.

If the boxes are in state 2 or state 3, then the action taken depends on whether the clicked box is already selected or not.

If unselected, change from state 2 to state 3 or vice versa, depending on the current state.

If selected, revert to state 1 with neither box selected.

The problem you have is that, if the boxes are in state 2 when clicked, they change to state 3 and vice versa *regardless of whether the clicked box is selected or not*

Am I right?

David Shaw

On Mon, 25 Jun 2018, 19:35 Dave, <ceda...@telus.net> wrote:
But if I decided I was being dyslexic and want to change my mind and say its deviating to the L, checking that would uncheck the R one

--
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+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/06f6b128-0af2-4019-9899-c25233749d00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark S.

unread,
Jun 25, 2018, 7:30:36 PM6/25/18
to TiddlyWiki
There we go -- "actions" was added to the checkbox widget in release 5.1.14.

-- Mark

Dave

unread,
Jun 25, 2018, 8:59:21 PM6/25/18
to TiddlyWiki
It's working after the upgrade (D'Oh!)

Thanks for your patience :)

Jed Carty

unread,
Jun 26, 2018, 8:10:25 AM6/26/18
to TiddlyWiki
Did you get a solution to this? It sounds like you did but I don't see it in the thread. If you did just ignore this. If not here are two solutions depending on how you want it to work.

Very simple, result in just one field:

\define tristateCheck(field:output option1:Left option2:Right)
<$checkbox field="""$field$""" checked="""option1""" unchecked=''>$option1$</$checkbox>
<$checkbox field="""$field$""" checked="""option2""" unchecked=''>$option2$</
$checkbox>
\end


<<tristateCheck>>

this version is a macro that is more complex but I think it more closely fits what you are asking for (put it in a tiddler tagged with $:/tags/Macro and then you can reuse it):

\define clear(field value:'') '<$action-setfield $field="""$field$""" $value="""$value$"""/>'
\define ExclusiveCheckbox(tiddler field1 field2 option1 option2 emptyValue:"")
<$tiddler tiddler="""$tiddler$""">
<$checkbox field="""$field1$""" checked="""$option1$""" unchecked="""$emptyValue$""" actions=<<clear """$field2$""" """$emptyValue$""">>>$option1$</$checkbox>

<$checkbox field="""$field2$""" checked="""$option2$""" unchecked="""$emptyValue$""" actions=<<clear """$field1$""" """$emptyValue$""">>>$option2$</$checkbox>
</$tiddler>
\end

! ExclusiveCheckbox macro

This macro gives two checkboxes that can act similarly to radio buttons in that only one will ever be checked at a time.
The differences are that with this you can unchecked the checked option and have none checked. You can also use this to have each checkbox affect a separate field.

|!Parameter |!Description |
|!tiddler |The tiddler that contains the fields that are affected by the checkboxes. |
|!field1 |The field set by the first checkbox. |
|!field2 |The field set by the second checkbox. |
|!value1 |The value put into `field1` when the first checkbox is checked. |
|!value2 |The value put into `field2` when the second checkbox is checked. |
|!emptyValue |The value that is put into a cleared field. |

Example: `<<ExclusiveCheckbox "$:/temp/testTid" field1 field2 yes no empty>>`

<<ExclusiveCheckbox "$:/temp/testTid" field1 field2 yes no empty>>

field1: {{$:/temp/testTid!!field1}}

field2: {{$:/temp/testTid!!field2}}

Dave

unread,
Jun 26, 2018, 2:52:16 PM6/26/18
to TiddlyWiki
Yes, my question was answered (the answer was "check your version first!") but thank you for providing this - it gives me more options for other similar needs I anticipate having in the near future!
Reply all
Reply to author
Forward
0 new messages