quasar icon indicating copy to clipboard operation
quasar copied to clipboard

Feature Request: Option to get rid of Checkbox intermediate state or change toggle order

Open KnowZero opened this issue 8 years ago • 22 comments

Quasar: 0.15-0.16

It would be nice to have the option of completely removing the intermediate state in checkboxes or maybe set the toggle order of states.

I know I can set the 'data' to the false-value or true-value but that isn't very convenient when working with dynamic forms.

Even if I set something like indeterminate-value="none" and don't specify a false-value, it still picks the indeterminate-value. (Even though it should technically pick the false value since that is null and not the intermediate value)

I would be able to get around this if I just change the indeterminate-icon="check_box_outline_blank", but then the user has to click twice to turn it on since I can't control the toggle order.

So the only way I can achieve close to the needed functionality is to flip everything around: false-value="yes" indeterminate-icon="check_box_outline_blank" unchecked-icon="check_box" checked-icon="check_box_outline_blank" keep-color

But having false-value as the true value isn't a very clean solution.

https://jsfiddle.net/wso1av4f/5/

KnowZero avatar May 21 '18 18:05 KnowZero

Hi,

Maybe I'm missing some point, but are you aware of the Boolean toggle-indeterminate prop? If you don't want the indeterminate state, just set it to Boolean "false"..

rstoenescu avatar May 21 '18 18:05 rstoenescu

@rstoenescu How do I do that? I tried

toggle-indeterminate="false", :toggle-indeterminate="false" and v-bind:toggle-indeterminate="false" and they don't seem to work. Am I doing something wrong?

KnowZero avatar May 21 '18 18:05 KnowZero

@rstoenescu From my understanding, toggle-indeterminate is false by default. But even if it is false by default, it still exists until user clicks once. But there should be an option to completely eliminate it. Look at my jsfiddle, the last checkbox is what I would like:

https://jsfiddle.net/wso1av4f/5/

With true toggle-indeterminate:

(start) indeterminate state-> (user clicks) -> false state-> (user clicks)-> true state-> (user clicks)->indeterminate state

With false toggle-indeterminate:

(start) indeterminate state-> (user clicks) -> false state-> (user clicks)-> true state-> (user clicks)->false state

My goal: (start) false state-> (user clicks)-> true state-> (user clicks)->false state

Aka, the intermediate state exists regardless of if it is true or false. The only way to completely get rid of intermediate state is by setting the v-model date to equal to true-value or false-value. But I would like to get rid of the intermediate state while having a null v-model value in data. Or at least ability to control the toggle order.

KnowZero avatar May 21 '18 19:05 KnowZero

@KnowZero have you fix may i know the solutions thanks

donvie avatar Aug 03 '18 02:08 donvie

The solution is to preset your model with the value you want it toggled to. Simple enough, especially since you need the model anyway to "store" the value.

I am not understanding the "dynamic" forms or "toggle order" bits (either). So, maybe that is where we are missing the point. Can you explain the use case / wish better please?

Scott

smolinari avatar Aug 03 '18 08:08 smolinari

I do need a null-is-false prop

gaby64 avatar Jan 17 '20 17:01 gaby64

@gaby64 :false-value="null" indeterminate-value="something-else"

rstoenescu avatar Jan 17 '20 18:01 rstoenescu

I have tried that, they are indeterminate on render

gaby64 avatar Jan 17 '20 18:01 gaby64

Works fine: https://codepen.io/rstoenescu/pen/YzPJYdv?editable=true&editors=101 Correct the initial value of the model... @gaby64

rstoenescu avatar Jan 18 '20 06:01 rstoenescu

undefined is my correct inital value for a property in an object array in a v-for, item.selected

this is the case for which it was not working

gaby64 avatar Jan 18 '20 10:01 gaby64

https://codepen.io/gaby64/pen/YzPREwm?editable=true&editors=101

the only change required to make it work is

checkbox.js

props: {
    value: {
      required: true,
      default: null
    }

gaby64 avatar Jan 20 '20 12:01 gaby64

Undefined isn't a proper value. It isn't a value. You aren't saving undefined in your database, are you?

Scott

smolinari avatar Jan 20 '20 15:01 smolinari

Undefined isn't a proper value. It isn't a value. You aren't saving undefined in your database, are you?

Scott

no

the point is its a temporary value, only used to mark the items as selected

once the chekbox is clicked, item.selected is a valid observable property.

in any case my proposed fix makes the default null, so undefined becomes null, perfectly valid, breaks nothing

gaby64 avatar Jan 20 '20 15:01 gaby64

the point is its a temporary value, only used to mark the items as selected

But, undefined won't mark the items selected and it makes no sense to do so. (unselected either). If is a case of needing to "preset" the value, you could just fill your data with a proper checked or unchecked value.

Scott

smolinari avatar Jan 20 '20 15:01 smolinari

the point is its a temporary value, only used to mark the items as selected

But, undefined won't mark the items selected and it makes no sense to do so. (unselected either). If is a case of needing to "preset" the value, you could just fill your data with a proper checked or unchecked value.

Scott

true defines them as selected, undefined is not selected you may want to waste cycles on such things when the answer is easily what I proposed and this works in other ui frameworks

its not part of the data, never will be, do you understand how someone might want to just have list items with chekboxes for an interface function and not have to pollute the data with presets that may not even be used?

gaby64 avatar Jan 20 '20 15:01 gaby64

I digress. We obviously have differing points of view on how to set up this component and its state.

Scott

smolinari avatar Jan 20 '20 16:01 smolinari

Just guessing, but maybe the OP wanted the same as I do when mentioning a "toggle order". The current toggle cycle is indeterminate --> unckecked --> checked. It would be very nice to have an option to invert the cycle, i.e. indeterminate --> checked --> unckecked.

Motivation: when the checkbox default state is indeterminate, clicking it once would check the option instead of unchecking it, which would arguably feel more natural to users.

leosdad avatar Apr 03 '20 17:04 leosdad

Toggle order available in v1.12

rstoenescu avatar May 31 '20 14:05 rstoenescu

Yes, thank you! A much welcome change.

leosdad avatar Jun 01 '20 13:06 leosdad

I need any falsy value (false, null, zero, undefined) to be displayed as unckecked. This is a common requisite when working with JSON data. Let's say I have three checkboxes that are bound to 3 variables, and one of them is omitted:

{
  "var1": false,
  // var2 is omitted
  "var3": null,
}

In this example I'd like all 3 values to show up as unckecked. Is this currently possible? Thanks.

leosdad avatar Jun 05 '20 22:06 leosdad