Page 1 of 1

Map checkboxes to backend via REST service

Posted: Wed Jun 19, 2013 7:36 pm
by Tom5954785

Hi all,

possibly a very silly question, but how do i map a group of checkboxes to send only the checked values to my backend ? Handling server side is no problem, i just cannot figure out how to send checked value and not sending unchecked values.
When i map each checkbox value to separate request parameters, they are all sent by REST even if they arent checked.


Map checkboxes to backend via REST service

Posted: Wed Jun 19, 2013 7:52 pm
by Kateryna Grynko

Hi Tom,

You can use the only request parameter - an array with selected items listed.

Create JavaScript code for the parameter without mapping, inside of function:

codevar list_of_checked_elements = Appery("mobilecheckboxgroup_11").find(":checked");

return $.map( list_of_checked_elements,
function(index, el) {
return {
name: el.name,
value: el.value
};
}
);/code


Map checkboxes to backend via REST service

Posted: Wed Jun 19, 2013 8:04 pm
by Kateryna Grynko

Or you can map "Selected" property:

Image


Map checkboxes to backend via REST service

Posted: Wed Jun 19, 2013 8:19 pm
by Tom5954785

Okay, is this compatible with settings GET and json ? Struggeling to get data sendt, but i might be temporarely blind on something here after a long day :)


Map checkboxes to backend via REST service

Posted: Wed Jun 19, 2013 8:35 pm
by Kateryna Grynko

Tom,

It's compatible only with POST request. For GET request you would need more difficult method.


Map checkboxes to backend via REST service

Posted: Wed Jun 19, 2013 9:33 pm
by Tom5954785

Changed to POST and form-urlencoded content type
Still, now sending only the last checkbox checked

Any other tricks ?

I miss a tutorial on using checkboxes btw..


Map checkboxes to backend via REST service

Posted: Thu Jun 20, 2013 6:41 am
by Tom5954785

solved it by serializing checkbox data

pre
var list_of_checked_elements = Appery("checkbox_group").find(":checked");
return $(list_of_checked_elements).serialize();
/pre