Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"The chain which can be yanked is not the eternal chain." -- G. Fitch


devel / comp.lang.javascript / four-state checkbox?

SubjectAuthor
* four-state checkbox?luserdroog
+- Re: four-state checkbox?Michael Haufe (TNO)
+* Re: four-state checkbox?Arno Welzel
|`* Re: four-state checkbox?The Natural Philosopher
| `- Re: four-state checkbox?Arno Welzel
`* Re: four-state checkbox?luserdroog
 +- Re: four-state checkbox?Arno Welzel
 `* Re: four-state checkbox?JJ
  `- Re: four-state checkbox?luserdroog

1
four-state checkbox?

<37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18219&group=comp.lang.javascript#18219

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a37:8685:0:b0:765:6a0f:8279 with SMTP id i127-20020a378685000000b007656a0f8279mr86712qkd.0.1691075094133;
Thu, 03 Aug 2023 08:04:54 -0700 (PDT)
X-Received: by 2002:a05:6808:209b:b0:3a7:3737:60fd with SMTP id
s27-20020a056808209b00b003a7373760fdmr16879263oiw.7.1691075093887; Thu, 03
Aug 2023 08:04:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Thu, 3 Aug 2023 08:04:53 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=24.107.183.247; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 24.107.183.247
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com>
Subject: four-state checkbox?
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Thu, 03 Aug 2023 15:04:54 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1375
 by: luserdroog - Thu, 3 Aug 2023 15:04 UTC

I want to make a control that looks like a checkbox but cycles through
4 states: { blank, checkmark, X-mark, questionmark }. What's the best
way to build such a thing. I'm thinking it wouldn't be too hard to make
a web component that just controls a span and flips through
{ "&nbsp;", "&#x...whatevers", ... "?" } strings.

Is there an existing element that's closer, like an <option> I guess?

Re: four-state checkbox?

<f77370fe-af7d-4074-9851-de01b4ec03bcn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18220&group=comp.lang.javascript#18220

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:622a:1899:b0:40d:4c6:bce6 with SMTP id v25-20020a05622a189900b0040d04c6bce6mr79377qtc.7.1691099172096;
Thu, 03 Aug 2023 14:46:12 -0700 (PDT)
X-Received: by 2002:a05:6808:1588:b0:39c:a74b:81d6 with SMTP id
t8-20020a056808158800b0039ca74b81d6mr32761337oiw.7.1691099171850; Thu, 03 Aug
2023 14:46:11 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Thu, 3 Aug 2023 14:46:11 -0700 (PDT)
In-Reply-To: <37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:6000:8900:6915:3953:297c:c5f1:149;
posting-account=hYRygAoAAABkmvJVmPilz9Q1TOjgPQAq
NNTP-Posting-Host: 2603:6000:8900:6915:3953:297c:c5f1:149
References: <37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f77370fe-af7d-4074-9851-de01b4ec03bcn@googlegroups.com>
Subject: Re: four-state checkbox?
From: tno@thenewobjective.com (Michael Haufe (TNO))
Injection-Date: Thu, 03 Aug 2023 21:46:12 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Michael Haufe (TNO) - Thu, 3 Aug 2023 21:46 UTC

On Thursday, August 3, 2023 at 10:04:58 AM UTC-5, luserdroog wrote:
> I want to make a control that looks like a checkbox but cycles through
> 4 states: { blank, checkmark, X-mark, questionmark }. What's the best
> way to build such a thing. I'm thinking it wouldn't be too hard to make
> a web component that just controls a span and flips through
> { "&nbsp;", "&#x...whatevers", ... "?" } strings.
>
> Is there an existing element that's closer, like an <option> I guess?

My first suggestion is choose a different way to accomplish this instead of abusing checkboxes which are meant to be binary (though less directly support an indeterminate state).

If you insist on using a checkbox for this, you can leverage a radio list and style it appropriately:

https://stackoverflow.com/a/33455783/153209

Re: four-state checkbox?

<kj6t23F83ojU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18221&group=comp.lang.javascript#18221

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.javascript
Subject: Re: four-state checkbox?
Date: Sat, 5 Aug 2023 14:19:15 +0200
Lines: 25
Message-ID: <kj6t23F83ojU1@mid.individual.net>
References: <37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net u29tFmpD4s2EJxygYEpKbg+pyKx7wD/6pDhSbGgYMnW1NDrVmr
Cancel-Lock: sha1:ud/AXFTOlPOQ0gkH1BatxAjeK7M= sha256:cb/xUsaEfpUjEw/P3zhtBIzHcIwgrRats+c2AFJJxA4=
Content-Language: de-DE
In-Reply-To: <37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com>
 by: Arno Welzel - Sat, 5 Aug 2023 12:19 UTC

luserdroog, 2023-08-03 17:04:

> I want to make a control that looks like a checkbox but cycles through
> 4 states: { blank, checkmark, X-mark, questionmark }. What's the best

A *checkbox* is there to show a *checked* or *unchecked* state.

If you need 4 different states, then it is not a checkbox but just some
element which shows 4 states. And in most cases a radio group is much
better for this - then users can clearly see what options are available
and can choose one of the options.

> way to build such a thing. I'm thinking it wouldn't be too hard to make
> a web component that just controls a span and flips through
> { "&nbsp;", "&#x...whatevers", ... "?" } strings.
>
> Is there an existing element that's closer, like an <option> I guess?

No. You need to implement it on your own or check if Angular, React, Vue
or Bootstrap have a component for that.

--
Arno Welzel
https://arnowelzel.de

Re: four-state checkbox?

<25ca36ef-bfb8-4db3-8b69-f49d6d22d872n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18222&group=comp.lang.javascript#18222

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:620a:245:b0:76c:d4b7:5dba with SMTP id q5-20020a05620a024500b0076cd4b75dbamr12905qkn.15.1691240109066;
Sat, 05 Aug 2023 05:55:09 -0700 (PDT)
X-Received: by 2002:a05:6870:3a0b:b0:1b3:d79c:f288 with SMTP id
du11-20020a0568703a0b00b001b3d79cf288mr4981195oab.3.1691240108571; Sat, 05
Aug 2023 05:55:08 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Sat, 5 Aug 2023 05:55:08 -0700 (PDT)
In-Reply-To: <37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=24.107.183.247; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 24.107.183.247
References: <37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <25ca36ef-bfb8-4db3-8b69-f49d6d22d872n@googlegroups.com>
Subject: Re: four-state checkbox?
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Sat, 05 Aug 2023 12:55:09 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2575
 by: luserdroog - Sat, 5 Aug 2023 12:55 UTC

On Thursday, August 3, 2023 at 10:04:58 AM UTC-5, luserdroog wrote:
> I want to make a control that looks like a checkbox but cycles through
> 4 states: { blank, checkmark, X-mark, questionmark }. What's the best
> way to build such a thing. I'm thinking it wouldn't be too hard to make
> a web component that just controls a span and flips through
> { "&nbsp;", "&#x...whatevers", ... "?" } strings.
>
> Is there an existing element that's closer, like an <option> I guess?

Thanks Michael and Arno. Here's my idea for the interface a little more
fleshed out:

<click-box cycle
states="empty checkmark xmark questionmark"
empty=""
checkmark="&x#..."
xmark="&x#..."
questionmark="?"></click-box>

Specifying the "cycle" attribute selects the (currently only) behavior
of cycling through states. The .value attribute/property of the
component will be reported as one of the strings from the "states"
attribute. If a state value itself is defined as an attribute then the
value of that attribute will be used as the label for visual display,
otherwise the value string will be used as the label.

This seems like it covers what I need, allowing extension without too
much YAGNI, and I can stick one in a <template> and then clone that
around where I need it, I think. Maybe it should also offer a .textContent
output.

Re: four-state checkbox?

<uam12e$1qlch$5@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18223&group=comp.lang.javascript#18223

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tnp@invalid.invalid (The Natural Philosopher)
Newsgroups: comp.lang.javascript
Subject: Re: four-state checkbox?
Date: Sat, 5 Aug 2023 18:31:58 +0100
Organization: A little, after lunch
Lines: 40
Message-ID: <uam12e$1qlch$5@dont-email.me>
References: <37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com>
<kj6t23F83ojU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 5 Aug 2023 17:31:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6070ec3361cce7739c0e75bcc0b9f94d";
logging-data="1922449"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/zGrDLURc09l53L65o3fANwFb2pyZIdao="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:DwyPnoqshj21hIGQx6GKAGB9LBw=
In-Reply-To: <kj6t23F83ojU1@mid.individual.net>
Content-Language: en-GB
 by: The Natural Philosop - Sat, 5 Aug 2023 17:31 UTC

On 05/08/2023 13:19, Arno Welzel wrote:
> luserdroog, 2023-08-03 17:04:
>
>> I want to make a control that looks like a checkbox but cycles through
>> 4 states: { blank, checkmark, X-mark, questionmark }. What's the best
>
> A *checkbox* is there to show a *checked* or *unchecked* state.
>
> If you need 4 different states, then it is not a checkbox but just some
> element which shows 4 states. And in most cases a radio group is much
> better for this - then users can clearly see what options are available
> and can choose one of the options.
>
>> way to build such a thing. I'm thinking it wouldn't be too hard to make
>> a web component that just controls a span and flips through
>> { "&nbsp;", "&#x...whatevers", ... "?" } strings.
>>
>> Is there an existing element that's closer, like an <option> I guess?
>
> No. You need to implement it on your own or check if Angular, React, Vue
> or Bootstrap have a component for that.
>
It's not hard to do in Javascript, simply have an onmousedown() event
that rotates an internal variable round 4 states and updates an onscreen
area with text, or selects e.g. a pseudo LED to light up to indicate the
state of the control.
I have long since given up using any HTML input controls. They look like
shit and they are hard to get looking nice across browser variations.

CSS styles the whole thing and javascript handles all user input. And
ajax calls update the server.

--
In theory, there is no difference between theory and practice.
In practice, there is.
-- Yogi Berra

Re: four-state checkbox?

<kj9fjbFkf52U2@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18224&group=comp.lang.javascript#18224

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.javascript
Subject: Re: four-state checkbox?
Date: Sun, 6 Aug 2023 13:47:56 +0200
Lines: 34
Message-ID: <kj9fjbFkf52U2@mid.individual.net>
References: <37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com>
<kj6t23F83ojU1@mid.individual.net> <uam12e$1qlch$5@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 3oA5YKOEgT9prHtRnorO0wRfYghRqnz6itNB2jThC5orptqPzz
Cancel-Lock: sha1:ySj0kpFfXPfHQUpKYJ5ezWEbdfM= sha256:LrFomnprd7mJdB9FMLd/0Wy87fzwhFvRdlU/jLexkYQ=
Content-Language: de-DE
In-Reply-To: <uam12e$1qlch$5@dont-email.me>
 by: Arno Welzel - Sun, 6 Aug 2023 11:47 UTC

The Natural Philosopher, 2023-08-05 19:31:

> On 05/08/2023 13:19, Arno Welzel wrote:
>> luserdroog, 2023-08-03 17:04:
>>
>>> I want to make a control that looks like a checkbox but cycles through
>>> 4 states: { blank, checkmark, X-mark, questionmark }. What's the best
[...]
>>> Is there an existing element that's closer, like an <option> I guess?
>>
>> No. You need to implement it on your own or check if Angular, React, Vue
>> or Bootstrap have a component for that.
>>
> It's not hard to do in Javascript, simply have an onmousedown() event
> that rotates an internal variable round 4 states and updates an onscreen
> area with text, or selects e.g. a pseudo LED to light up to indicate the
> state of the control.

If the OP would be able to do so, he would not have asked here.

> I have long since given up using any HTML input controls. They look like
> shit and they are hard to get looking nice across browser variations.
>
> CSS styles the whole thing and javascript handles all user input. And
> ajax calls update the server.

And all this is *not* accessible. HTML input controls can be styled
*and* you can override them with your own components. But not using them
at all is often a very bad decision.

--
Arno Welzel
https://arnowelzel.de

Re: four-state checkbox?

<kj9fp0Fkf52U3@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18225&group=comp.lang.javascript#18225

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.javascript
Subject: Re: four-state checkbox?
Date: Sun, 6 Aug 2023 13:50:56 +0200
Lines: 31
Message-ID: <kj9fp0Fkf52U3@mid.individual.net>
References: <37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com>
<25ca36ef-bfb8-4db3-8b69-f49d6d22d872n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 2XfIaX19OoJN5lVLFftvMQPrLjTCCH05/3Hmz4DqL6rh7ryLSk
Cancel-Lock: sha1:gLphxksl5qKiQ15aQJvH48EcFjo= sha256:W3WV1l3PxqQrGnt7hpitOqvwGzYamkmHydeT1RviFwk=
Content-Language: de-DE
In-Reply-To: <25ca36ef-bfb8-4db3-8b69-f49d6d22d872n@googlegroups.com>
 by: Arno Welzel - Sun, 6 Aug 2023 11:50 UTC

luserdroog, 2023-08-05 14:55:

> On Thursday, August 3, 2023 at 10:04:58 AM UTC-5, luserdroog wrote:
>> I want to make a control that looks like a checkbox but cycles through
>> 4 states: { blank, checkmark, X-mark, questionmark }. What's the best
>> way to build such a thing. I'm thinking it wouldn't be too hard to make
>> a web component that just controls a span and flips through
>> { "&nbsp;", "&#x...whatevers", ... "?" } strings.
>>
>> Is there an existing element that's closer, like an <option> I guess?
>
> Thanks Michael and Arno. Here's my idea for the interface a little more
> fleshed out:
>
> <click-box cycle
> states="empty checkmark xmark questionmark"
> empty=""
> checkmark="&x#..."
> xmark="&x#..."
> questionmark="?"></click-box>

Maybe you should consult this:

<https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements>

--
Arno Welzel
https://arnowelzel.de

Re: four-state checkbox?

<vyjudl2tpmj9$.mo4v45a7o4bt.dlg@40tude.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18226&group=comp.lang.javascript#18226

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jj4public@outlook.com (JJ)
Newsgroups: comp.lang.javascript
Subject: Re: four-state checkbox?
Date: Mon, 7 Aug 2023 12:04:03 +0700
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <vyjudl2tpmj9$.mo4v45a7o4bt.dlg@40tude.net>
References: <37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com> <25ca36ef-bfb8-4db3-8b69-f49d6d22d872n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="37b8bc24a1b214a874b754a36b460e8e";
logging-data="2878676"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rEqNsqfNGsK1Y0EJMx73bcO1O5rOj0sg="
User-Agent: 40tude_Dialog/2.0.15.84
Cancel-Lock: sha1:Upjo9bPfzqCtp8KKm4tQvfPr/as=
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
 by: JJ - Mon, 7 Aug 2023 05:04 UTC

On Sat, 5 Aug 2023 05:55:08 -0700 (PDT), luserdroog wrote:
> On Thursday, August 3, 2023 at 10:04:58 AM UTC-5, luserdroog wrote:
>> I want to make a control that looks like a checkbox but cycles through
>> 4 states: { blank, checkmark, X-mark, questionmark }. What's the best
>> way to build such a thing. I'm thinking it wouldn't be too hard to make
>> a web component that just controls a span and flips through
>> { "&nbsp;", "&#x...whatevers", ... "?" } strings.
>>
>> Is there an existing element that's closer, like an <option> I guess?
>
> Thanks Michael and Arno. Here's my idea for the interface a little more
> fleshed out:
>
> <click-box cycle
> states="empty checkmark xmark questionmark"
> empty=""
> checkmark="&x#..."
> xmark="&x#..."
> questionmark="?"></click-box>
>
> Specifying the "cycle" attribute selects the (currently only) behavior
> of cycling through states. The .value attribute/property of the
> component will be reported as one of the strings from the "states"
> attribute. If a state value itself is defined as an attribute then the
> value of that attribute will be used as the label for visual display,
> otherwise the value string will be used as the label.
>
> This seems like it covers what I need, allowing extension without too
> much YAGNI, and I can stick one in a <template> and then clone that
> around where I need it, I think. Maybe it should also offer a .textContent
> output.

That would be a custom input interface element. e.g.

https://jsbin.com/dixapihuto/1/edit?html,css,js,output

Re: four-state checkbox?

<b6cba8d4-5a6e-4b6f-b056-40b4005627a3n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18228&group=comp.lang.javascript#18228

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:622a:1a9b:b0:401:df93:4d8 with SMTP id s27-20020a05622a1a9b00b00401df9304d8mr41748qtc.11.1691420183060;
Mon, 07 Aug 2023 07:56:23 -0700 (PDT)
X-Received: by 2002:a05:6808:138c:b0:3a1:eb8a:203d with SMTP id
c12-20020a056808138c00b003a1eb8a203dmr17207727oiw.11.1691420182687; Mon, 07
Aug 2023 07:56:22 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Mon, 7 Aug 2023 07:56:22 -0700 (PDT)
In-Reply-To: <vyjudl2tpmj9$.mo4v45a7o4bt.dlg@40tude.net>
Injection-Info: google-groups.googlegroups.com; posting-host=24.107.183.247; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 24.107.183.247
References: <37b72956-7171-4f6a-baf5-0bcdb2e151b5n@googlegroups.com>
<25ca36ef-bfb8-4db3-8b69-f49d6d22d872n@googlegroups.com> <vyjudl2tpmj9$.mo4v45a7o4bt.dlg@40tude.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b6cba8d4-5a6e-4b6f-b056-40b4005627a3n@googlegroups.com>
Subject: Re: four-state checkbox?
From: luser.droog@gmail.com (luserdroog)
Injection-Date: Mon, 07 Aug 2023 14:56:23 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: luserdroog - Mon, 7 Aug 2023 14:56 UTC

On Monday, August 7, 2023 at 12:04:12 AM UTC-5, JJ wrote:
> On Sat, 5 Aug 2023 05:55:08 -0700 (PDT), luserdroog wrote:
> > On Thursday, August 3, 2023 at 10:04:58 AM UTC-5, luserdroog wrote:
> >> I want to make a control that looks like a checkbox but cycles through
> >> 4 states: { blank, checkmark, X-mark, questionmark }. What's the best
> >> way to build such a thing. I'm thinking it wouldn't be too hard to make
> >> a web component that just controls a span and flips through
> >> { "&nbsp;", "&#x...whatevers", ... "?" } strings.
> >>
> >> Is there an existing element that's closer, like an <option> I guess?
> >
> > Thanks Michael and Arno. Here's my idea for the interface a little more
> > fleshed out:
> >
> > <click-box cycle
> > states="empty checkmark xmark questionmark"
> > empty=""
> > checkmark="&x#..."
> > xmark="&x#..."
> > questionmark="?"></click-box>
> >
> > Specifying the "cycle" attribute selects the (currently only) behavior
> > of cycling through states. The .value attribute/property of the
> > component will be reported as one of the strings from the "states"
> > attribute. If a state value itself is defined as an attribute then the
> > value of that attribute will be used as the label for visual display,
> > otherwise the value string will be used as the label.
> >
> > This seems like it covers what I need, allowing extension without too
> > much YAGNI, and I can stick one in a <template> and then clone that
> > around where I need it, I think. Maybe it should also offer a .textContent
> > output.
> That would be a custom input interface element. e.g.
>
> https://jsbin.com/dixapihuto/1/edit?html,css,js,output

Very nice. I took a slight peek while ironing out the creases in mine.
I haven't quite figured out the next tweak where I want to convert
the value to/from a string by doing a map/reverse-map through the
label strings. Like, if this "clickbox" is a cell in a table I want to easily
convert the table contents to/from a CSV text file. And for this type of
cell it should read and write the unicode checkmark character and
internally recognize/store the value as "checkmark".

click.html:

<html>
<body>
<click-box cycle
states="empty checkmark xmark questionmark"
empty=""
checkmark="&check;"
xmark="&#x2716;"
questionmark="?"></click-box>
</body>
<script src="click.js"></script>
</html>

click.js:

const clickBoxTemplate = document.createElement( "template" );
clickBoxTemplate.innerHTML = `
<style>
input{
text-align: center;
cursor: default;
}
</style>
<input id="box" type="text" readonly>
`;

function max( x, y ){
return y > x ? y : x;
}

class ClickBox extends HTMLElement {
constructor() {
super();
this.attachShadow( {mode:"open"} );
this.shadowRoot.appendChild( clickBoxTemplate.content.cloneNode(true) );
if( this.hasAttribute( "cycle" ) ){
this._states ( this.hasAttribute("states") ?
this.getAttribute("states") : "empty true false" ).split( " " );
console.log( this._states );
this._stateNumber = 0;
this._state = this._states[ this._stateNumber ];
let box = this.shadowRoot.querySelector("#box");
let size = this._states.
map(x=>this.hasAttribute(x)?this.getAttribute(x):x).
map(x=>x.length).
reduce( max );
console.log( size );
box.setAttribute( "size", size );
}
}
increment() {
this._stateNumber = (this._stateNumber + 1) % this._states.length;
this._state = this._states[ this._stateNumber ];
}
draw() {
let box = this.shadowRoot.querySelector("#box");
console.log( box );
this.value = this._state;
console.log( this.value );
box.toggleAttribute( "readonly" );
if( this.hasAttribute( this.value ) ){
box.value = this.getAttribute( this.value );
} else {
box.value = this.value;
}
box.toggleAttribute( "readonly" );
box.blur();
}
click( event ){
event.preventDefault();
this.increment();
this.draw();
return;
}
connectedCallback() {
this.shadowRoot.querySelector("#box").addEventListener( "click", (e)=>this.click(e) );
}
disconnectedCallback() {
this.shadowRoot.querySelector("#box").removeEventListener();
}
}

window.customElements.define( "click-box", ClickBox );

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor