Tom5954785
Posts: 0
Joined: Fri Jun 14, 2013 9:24 pm

Map checkboxes to backend via REST service

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.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Map checkboxes to backend via REST service

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Map checkboxes to backend via REST service

Or you can map "Selected" property:

Image

Tom5954785
Posts: 0
Joined: Fri Jun 14, 2013 9:24 pm

Map checkboxes to backend via REST service

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 :)

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Map checkboxes to backend via REST service

Tom,

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

Tom5954785
Posts: 0
Joined: Fri Jun 14, 2013 9:24 pm

Map checkboxes to backend via REST service

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..

Tom5954785
Posts: 0
Joined: Fri Jun 14, 2013 9:24 pm

Map checkboxes to backend via REST service

solved it by serializing checkbox data

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

Return to “Issues”