True & False Are NOT Boolean!?

Hi there,

Recently, I’ve been receiving new strange errors on my page, Wix Skin Failed , and this weird error:

The checked parameter that is passed to the checked method cannot be set to the value false . It must be of type boolean .

The checked parameter that is passed to the checked method cannot be set to the value true . It must be of type boolean .

Knowing that the switches are connected to the database, and not set by code.
I always receive the two errors together.

Any ideas? Help is appreciated.
Ahmad

Have a read of Checkbox.
https://www.wix.com/corvid/reference/$w.Checkbox.html

If the ‘checked’ property indicates whether my checkbox was checked, what is the purpose of ‘value’?
value allows you to associate a label with your checkbox.

Let’s say you ask visitors to indicate their music preferences by checking one or more checkboxes. You can write code using the value property to save visitors’ selections as strings (rock, jazz, reggae) in your database collection.

https://www.wix.com/corvid/reference/$w.Checkbox.html#checked
checked
Sets or gets whether a checkbox is checked.

Description
Setting the checked property to true places a check in the checkbox. Setting it to false removes the check from the checkbox.

Getting the checked property returns whether the checkbox is checked or unchecked.

https://www.wix.com/corvid/reference/$w.Checkbox.html#value
value
Sets or gets a checkbox’s value.

Description
The value property is not related to whether the checkbox is checked or not. To determine the checked status of a checkbox, use the checked property.

The value property is used for storing a value that is associated with the checkbox.

It is not considered when evaluating the checkbox’s validity and it does not trigger an onChange event when the value is modified.

Even if a checkbox is connected to a dataset, its value property is not related to the value of the collection field it is connected to. The field’s value is determined by the checkbox’s checked property.

Note
Changing a checkbox’s value in code does not trigger an onChange event.

Hi @givemeawhisky , thanks for your reply.

I’m aware of switches use, I’m not trying to set a value to or get a value from the switch, I’m only checking the switch (checked) status to run some code according to its status.

And in my case, the switch is connected to the dataset with a Boolean field, if the field value is true (checked), the switch is checked and vice versa, it was working fine for almost a week, but start returning these errors only today.

As a result of the error above, many other errors were risen, and to solve it as quick as possible I had to disconnect the switch from the dataset, and get its value directly from the database.

I don’t know what’s the reason of this, if the passed parameter is either true or false, then it’s Boolean, then why it’s returning an error.

This is happening with me across ALL live sites (12 sites). Toggle switches are not reading or recording user input across all datasets!

All the sites previously had this working.

Speaking to support about this right now. But #CorvidDevs can you look into this please

Support Ticket No. 1601424846

#Corvidbug #toggleswitchesbroken

I noticed that if you set Boolean in the dataset and it’s checked it’s returning “true” as it should; however, if it’s NOT checked it’s returning “undefined” why? why is it not returning “False”?

If it’s a Boolean it should return either “true” or “false”,
unless you add to the Boolean field a third option,

  1. checked with green v = true
  2. Checked with red x = false
  3. Unchecked = undefined

Otherwise it confusing.

My code is working fine, because I use “if value is true”,
but you can’t use “if value is false” as it’s behaving strangely and not working as it should.
it seems you have to use undefined instead of false, which is odd for a Boolean

-EDIT=
Sorry for re-opening such an old thread, the date shows only the month and the year shows only when you hover over the date… so my bad, but the post still applies…
didn’t see the timeline to the right, looking at the posts themselves :confused:

try to keep your if-else-conditions simple…

instead of…
if(value === true) {.......} else {......}

do just…
if(value) {.......} else {......}

This way UNDEFINED and FALSE would be like one and same result → FALSE, no matter if wix provides a FALSE or UNDEFINED for unchecked values.

1 Like

I am not sure this is useful but, I thought I should mention it in a dataset, when adding Boolean values fields, you can set its default value, and if you don’t set this or manually toggle them all, then you get an undefined error.

Click the title of the dataset Boolean fields at the top then edit then default value to set it.

@CODE-NINJA’s advice is correct but I wanted to elaborate on this a bit more with a couple points as to why this is generally the correct way to do this, at least in JavaScript.

JS itself lacks strongly typed declarations and has no native notion of a ternary (or nullable) object. Instead every object can have either a value, null, or be undefined. If JS had type declarations we might be able to differentiate better using a nullable type like bool? which would explicitly declare that while a variable may have a boolean value it can also be null. But we don’t have this available to us.

Instead we leverage undefined, null, or both to represent certain edge cases. In this case entries in your database have 3 potential values for a boolean field:

  • true
  • false
  • Empty (aka undefined)

Empty is not false which is why we don’t want to assume and tell the frontend application that it’s false when it isn’t. Rather we tell frontend that it’s undefined which is an important piece of information. It lets us know that this particular field doesn’t have a value.

More practically then these values mean:

  • true = User checked the box
  • false = User unchecked the box
  • Empty (aka undefined) = User hasn’t engaged with the box

However in addition to doing the defensive programming that @CODE-NINJA mentioned above you can also do one of the following:

In the second option you’ll then get your queries returned so that the field is reported as the default value whenever it is empty. For example this database looks like:

But when we query it our items array says:

[
  {
    "boolean": false,
    "title": "test2"
  },
  {
    "boolean": false,
    "title": "TEST"
  }
]
1 Like

Ok, that makes sense.

But what is → null? I asked myself this question already once in the past.

Is null = another word for undefined.

Comparing for example google Chrome and Microsoft-Edge, EDGE uses null as of my knowledge and CHROME → undefined. But maybe i misunderstood something.

Is null = 0 ???
Is null still something different as undefined → so → null ← is still defined but false?

Why do i need nulll in which cases ?

Is null an number?

What’s the exact definition of null.

As we can see, that → null ← is somekind of we don’t really know how to define, at least it looks like that.

Javascript having both null and undefined is a bit of a mistake IMO but we can’t fix that one :slight_smile:

I’m not familiar with Edge’s JS engine but since it’s now Chromium under the hood it’s surprising to hear it’s different from Chrome.

Anyways there is a bit of a difference:

  • undefined = the variable was declared but never given a value
  • null = the variable was declared and given a value; but it represents null
1 Like