Editor - set default value of checkbox - unespected behavior.

Editor - set default value of checkbox - unespected behavior.

Tester2017Tester2017 Posts: 145Questions: 23Answers: 17

Maybe I am overlooking something, but I always worked with false/true 0/1 unchecked/checked.

To set a checkbox default as checked I have to give as default value a 0. Every other value will uncheck the checkbox.

Is there a reason for this behavior?

This code will give a checked checkbox:

            {
                label: `Hide group:`,
                name: `group.hide`,
                def: 0,
                type: `checkbox`,
                separator: `,`,
                options: [
                    ``
                ]
            },

And this an unchecked one:

            {
                label: `Hide group:`,
                name: `group.hide`,
                def: 1,
                type: `checkbox`,
                separator: `,`,
                options: [
                    ``
                ]
            },

This question has an accepted answers - jump to answer

Answers

  • Tester2017Tester2017 Posts: 145Questions: 23Answers: 17

    I am sorry, forget my question as I indeed was overlooking something. In other words: I made a mistake and already found a solution for it.

  • Tester2017Tester2017 Posts: 145Questions: 23Answers: 17
    Answer ✓

    For to let it work the way I wished I needed to change to code the following way:

               {
                    label: `Hide group:`,
                    name: `group.hide`,
                    def: 0,
                    type: `checkbox`,
                    separator: `,`,
                    options: [
                        { label: ``,value: 1 }
                    ],
                    unselectedValue: 0
              },
    
  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    Thanks for posting back - yes the unselectedValue option of checkbox is the way to do this.

    Allan

This discussion has been closed.