Iterate through editor checkboxes
Iterate through editor checkboxes

I have a checkbox field setup in the editor and would like to iterate through the checkboxes to see which ones have been selected or not selected once the user closes the editor. Is there an example on how to do this? I'm using editor.on( 'close', function ( e, type ) to do this.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Could you explain what the goal is here please?
If we take this example you wouldn’t iterate through the checkboxes, but rather listen for
postEdit
which will give you the new data for the row that has been edited.Allan
This goes back to my problem with dynamically creating a list of checkboxes and being able to 'check' them as needed.
I'm creating a list of checkboxes in the editor.on('open') using:
editor.add({
label: "Work Order Items:",
name: "items",
type: "checkbox",
options: [{label:"1", name:"cb1", value:1, id:1},{label:"2", name:"cb2", value:0, id:2},{label:"3", name:"cb3", value:0, id:3}, {label:"4", name:"cb4", value:0, id:4}],
});
Once the user selects 'Update', I'd like to manually update the database looking at which of the checkboxes they've selected.
Would you not do that on the server-side rather than the client-side? What is your server-side environment (e.g. PHP / .NET / NodeJS / etc)?
When the form is submitted, Editor submits data in the format described here - so you could use
$_POST['data'][key]['items']
(assuming PHP, and wherekey
is the key in the data array - you'd use aforeach
loop to get that). That would give you the array of values that were selected, so you could then enact whatever database update you need.Allan
I think I'm failing to understand a few things and will go through the documentation better.
Using your joinArray example, in an "editor.on("open")..." I added:
editor.add( {
type: "checkbox",
label: "Years:",
name: "years",
options: [
2012,
2013,
2014,
2015
]
} );
This shows up in the editor just fine, but if I look at the data passed to the server in an editor.on("preEdit",...", I don't see this data. Do I need to add something to the datatable itself? I think I'm just missing a simple part that I haven't found in any example yet.
I do see the data being passed to the server in $_POST. Thank you for your help.