Page 1 of 1

Saving data from checkbox list

Posted: Mon Feb 17, 2014 10:30 pm
by Homan Mohammadi

Hello, we are trying see which checkboxes from a list of checkboxes were selected, and then save each selection as an entry into the database. The javascript code we are using is
Appery("mobilecheckboxgroup_11").find("input:checked").each(function(){
sharing_add.execute({data: {"collName":"users", "id":$(this).val()}});
});

The parameter we are getting from the checkbox and saving into the database (along with other information) is a pointer to the users table (in the form of their user id).

We are getting a 400 response when we submit as "Creation and modification objects with system fields not allowed."

We've checked some other responses such as getsatisfaction.com/apperyio/topics/variable_create_service_with_checkbox, but this is not working (we think it might be different because the parameter we are working with is a pointer in the database). Please let us know. Thanks!


Saving data from checkbox list

Posted: Tue Feb 18, 2014 1:34 am
by Alena Prykhodko

Hi Homan,

You are right, the problem was with the pointer collumn type.
And there is a solution:

pre
Appery("mobilecheckboxgroup_11").find("input:checked").each(function(){

Code: Select all

 var userId = $(this).val(); 
 create_dogs.execute({"data": {"_users": {"collName": "users", "_id": userId } }}); 

});
/pre

Note: don't confuse "_users" and "users".

"_users" - is your collection field name you have added as pointer to "users" pointer.

Please find more information about Pointer type here http://docs.appery.io/documentation/b...
Also we recommend to practice at creating create/update services http://docs.appery.io/documentation/b... .


Saving data from checkbox list

Posted: Tue Feb 18, 2014 4:44 am
by Homan Mohammadi

Hi Alena,

Thank you for the quick response. We tried the changes you suggested, but still can't seem to get the create service to work. We still get the same 400 response. Below are the JS code and a screenshot of the collection.

JS:
Appery("mobilecheckboxgroup_11").find("input:checked").each(function(){
var userId = $(this).val();
sharing_add.execute({"data": {"users": {"collName": "users", "id": userId } }});
});

Collection:
Image

Thank you so much for your help!


Saving data from checkbox list

Posted: Tue Feb 18, 2014 8:42 pm
by Maryna Brodina

Hello! Do you want to add line in sharing table and fill in recipient column (pointer to Users collection), right? Then you would need to pass in service something like this presharing_add.execute({"data": {"recipient":{"collName": "users", "id": userId }}});/pre


Saving data from checkbox list

Posted: Tue Feb 18, 2014 8:57 pm
by Homan Mohammadi

Got it, thank you so much!