Dynamically Create Checkbox Items From Database Textarea Content

Dynamically Create Checkbox Items From Database Textarea Content

Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

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

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

    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 the checkbox type to update the list of options. You could attach an event listener to open to know when the list should be updated.

    Allan

  • Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

    Yes each row has its each row of checkboxes. The updating is working fine. I just wish to alter this part,

            options: {
            "UCEPROTECT BL1": "UCEPROTECT BL1",
            "Backscatterer":  "Backscatterer"
            },
    

    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?

This discussion has been closed.