Post for checkbox fields

Post for checkbox fields

russlevyrusslevy Posts: 15Questions: 6Answers: 0
edited August 2015 in Editor

Hi,

I have a checkbox field which has value 1 or 0. I initialize it with options: [{label: '', value: 1}]. If the field is not checked on post then it is not submitted at all. Is there a way to get this submit with 0? Also in general it submits within an array. It would be better if there could be a checkbox which simply submitted 1 or 0.

My solution in the meantime is

editor.on('preSubmit', function(e, data, action){
            data.data.done = (typeof data.data.done == 'undefined') ? 0 : 1
        })

but wondering if there is a better way of doing this.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Hi,

    This is just the way that HTML checkboxes work I'm afraid. If nothing is checked, then an empty value is sent.

    If you have a simple boolean, then a radio input (radio) might be a better option. Otherwise a custom field type would be required.

    Allan

This discussion has been closed.