Auto select checkboxes in form

Auto select checkboxes in form

TronikTronik Posts: 122Questions: 28Answers: 1

Hi,

I have one field containing two checkboxes as shown below, I need them to be pre checked when form is shown.
I've tried with set and multiSet but can't really get it to work.
Would really appreciate some guidance on this.

This is current code

{
        type:  "checkbox",
            label: "Store:",
            name:  "store",
            options: [
                { label: "Store B", value: 2 },
                { label: "Store C", value: 3 }
             ]
   }

Obvioulsy below code doesnt work as needed but thats what Im experimenting with

editor.on( 'open', function ( e, type ) {
    
    editor.field( 'store' ).set( 2 );
    editor.field( 'store' ).set( 3 );
    editor.field( 'store' ).disable();
} );

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Use: def: [2, 3] in your options for the field to set the default value.

    The problem with using .set(2) ... .set(3) is that that is setting the value to 2, then 3. You could use .set([2, 3]) but if you are wanting a default value then fields.def is the way to do it.

    Allan

  • TronikTronik Posts: 122Questions: 28Answers: 1

    That easy.
    Thanks a lot

This discussion has been closed.