Dynamically Create Checkbox Items From Database Textarea Content
Dynamically Create Checkbox Items From Database Textarea Content
I have a textarea in my database which contains a comma separated list of values. These vary depending on the table row. Is it possible to create my checkbox items dynamically in editor from this comma separated string? Hardcoded it is working fine with a couple of test static values (see the field 'Exclude Real Time Blacklists'):
var editor = new $.fn.DataTable.Editor({
"ajax" : {
"url" : "table.module.php",
"type" : "POST",
"data" : function(d) {
d.user_id = "126";
}
},
"table" : "#module",
"fields" : [
{
"label" : "Monitor Type",
"name" : "monitor_type",
"type" : "text"
}, {
"label" : "Monitor Name",
"name" : "name",
"type" : "text"
}, {
"label" : "Remark",
"name" : "remark",
"type" : "textarea"
}, {
"label" : "Content Match",
"name" : "string",
"type" : "text"
}, {
type: "checkbox",
label: "Exclude Real Time Blacklists (RBL's):",
name: "blacklist_exclude",
options: {
"UCEPROTECT BL1": "UCEPROTECT BL1",
"Backscatterer": "Backscatterer"
},
separator: ','
}, {
"label" : "Status",
"name" : "active",
"type" : "select",
"ipOpts" : [{
"label" : "Active",
"value" : "Active"
}, {
"label" : "Inactive",
"value" : "Inactive"
}]
}]
});
The database column currently holds data like so;
Backscatterer,UCEPROTECT BL1
Can I use that data to create my checkbox options dynamically so they are different for each row of the table?
I think it is possible to use editor.get( 'blacklist_exclude' )
to access the content perhaps?
Many thanks
Chris
This question has an accepted answers - jump to answer
Answers
So each row has its own defined list of checkboxes, which must be displayed and then the checked options stored somewhere else? Use the
update()
method of thecheckbox
type to update the list of options. You could attach an event listener toopen
to know when the list should be updated.Allan
Yes each row has its each row of checkboxes. The updating is working fine. I just wish to alter this part,
From being static code to dynamically populated from the column called 'blacklist_exclude' within each row of my table.
Each row has a cell called 'blacklist_exclude' which contains a comma separated list of values. So like this,
UCEPROTECT BL1,Backscatterer
I just wish to create my checkbox options from this data. Can I use
editor.get( 'blacklist_exclude' )
to get the values and create the options?