My checkbox does not correctly return TRUE/FALSE status
My checkbox does not correctly return TRUE/FALSE status
https://live.datatables.net/razujato/1/edit
Debugger code (debug.datatables.net):
editor.on('preSubmit', function (e, json, data, action) {
let opt = this.field('options');
console.log(opt.val()[0]);
});
Error messages shown: undefined value.
Description of problem:
Once in the editor modal, when the checkbox is checked and then I press the Refresh button, the code returns "true". BUT when the checkbox is NOT checked and I press the Refresh button, the code returns 'undefined'
How do I get the code to return the value 'false' instead of 'undefined'
Regards! ![]()
This question has accepted answers - jump to:
Answers
Hi,
You need to use the
unselectedValueoption ofcheckboxif you want it to have a value when no checkbox is selected. You are using it more as a radio box there, which is why this is required.Allan
Hi
Thanks for your response, I got it working by returning the TRUE/FALSE value, using the following code snippet.
{label: "Mostrar opciones:",name: "options",type: "checkbox",//separator: '|',options: [{ label: '', value: true }],unselectedValue: false,def: false}How do I make the delivered value be of type boolean? Currently the value is of type Array and the result is [false] or [true], otherwise if I enable the
{ separator: '|' }, the result is type string "false" or "true".You can see my test code here: https://live.datatables.net/razujato/2/edit
Regards!
Client-side use
fields.getFormatterto cast the value. The reason for this is that the value is read from theinputelement which is always a string.At the server-side you might need to cast it there if you are expecting a true Boolean there. Http parameters are type-less unfortunately.
Allan
Hi Allan
I thank you very much for your answers, they were very accurate and I was able to solve it.
Regards!