Auto select checkboxes in form
Auto select checkboxes in form
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
This discussion has been closed.
Answers
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 thenfields.def
is the way to do it.Allan
That easy.
Thanks a lot