How to use checkbox on editor field with boolean values?

How to use checkbox on editor field with boolean values?

hjohnsickhjohnsick Posts: 7Questions: 4Answers: 0

I am using the DataTables Editor and want to use a checkbox in the editor form. The checkbox displays but the value is always 1. I want the value to be 0 when the checkbox is not selected and when it is check the value should be 1.
The last example here, https://editor.datatables.net/reference/field/checkbox, seems to be what I want but when I check the value of the checkbox it always shows the value as 1 whether it is checked or not.

    let editor = new DataTable.Editor({
        fields: [
            {
                label: 'Is Urgent',
                name: 'IsUrgent',
                type: 'checkbox',
                options: [
                    { label: 'Yes', value: 1 }
                ],
                separator: '',
                unselectedValue: 0
            },
        ],
        idSrc: 'DisplayMessageId',
        table: '#DataGrid'
    });

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,991Questions: 87Answers: 421
    Answer ✓

    Your Screenshot shows the values you are receiving from the server, right? That is not the payload, is it? Probably something wrong with your server script?!

    I use the exact same syntax as you do and this my payload of two of those fields. One checkbox is checked and the other one is unchecked:

  • hjohnsickhjohnsick Posts: 7Questions: 4Answers: 0

    Yeah I'm not sure what the issue was but I didn't change anything and now it is working as expected...

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

    We'll call it a win then :). Good to hear it is working though, and thanks for the update.

    Allan

Sign In or Register to comment.