Page 1 of 2

How to update multiple objects in a collection on a single click

Posted: Wed Jul 31, 2013 8:59 am
by vipul

I have a check box in a grid of 3 columns. which displays list of students through list service which runs on load of the page.
Now i have to select the check box for the students who are present in the class and then on click of submit button its value should be updated in to the database.
in short how will i run update service to updated multiple object on a single click of a button.


How to update multiple objects in a collection on a single click

Posted: Wed Jul 31, 2013 10:58 am
by Maryna Brodina

Hello! "On a single click" you can update only one record. You would need to run update service for each record in a loop.


How to update multiple objects in a collection on a single click

Posted: Wed Jul 31, 2013 12:17 pm
by vipul

Hello!

this grid is of 3 columns and 1 row.
ex : Name StudentId checkbox
values comes in this grid form previous page.
so let say i got 2 values in this grid
ex:
Marina 1234 checkbox
Vipul 1111 checkbox

here student id is the object id of that particular row in the collection

now when i mark Marina as present by selecting the check box
it should run update service by picking 1234 as the object id

how will I do that??

I know this is a lame question but i m new to Appery so pls help


How to update multiple objects in a collection on a single click

Posted: Wed Jul 31, 2013 12:53 pm
by Maryna Brodina

1) You would need to configure Update service to make so that record id will be mapped to localStorage variable;
2) using JS define all checked checkboxes (http://api.jquery.com/checked-selector/). For checked checkboxes (http://api.jquery.com/each/) you need to find parent element with tr tag (http://api.jquery.com/parents/) because you're working with a Grid, tr is a table row, if you're working with another component (not Grid) then you need to find corresponding parent element and in this parent element find element which contains records id (http://api.jquery.com/find/). Save id to localStorage variable, call the service codeserviceName.execute({});/code


How to update multiple objects in a collection on a single click

Posted: Fri Aug 02, 2013 12:34 pm
by vipul

Hi Marina
thanks for your help
I am putting a piece of my JS here
can you pls help..!!

var isChecked=$('input[name=mobilecheckbox_27]').is(':checked');
alert(isChecked); // Here i always get false whether it is checked or unchecked
//var localId=localStorage.getItem('object_id');
if(isChecked)
{
var parentEls = $("mobilecheckbox_27").parents("tr");
alert(parentEls); // It is also not showing any thing
$(parentEls).each(function(index) {
alert(index + ": " + $(this).text());
console.log(index + ": " + $(this).text());
});
}

thats why I am not able to proceed
and also let me know how to find particular child element after this


How to update multiple objects in a collection on a single click

Posted: Fri Aug 02, 2013 1:10 pm
by Maryna Brodina

Hi,
1) instead codevar isChecked = $('input[name=mobilecheckbox_27]').is(':checked');/code try codevar isChecked = Appery("mobilecheckbox_27").find("input").is(":checked");/code
2) [quote:]find particular child element[/quote] see http://api.jquery.com/children/


How to update multiple objects in a collection on a single click

Posted: Fri Aug 02, 2013 1:19 pm
by vipul

with this script also it is showing false only


How to update multiple objects in a collection on a single click

Posted: Fri Aug 02, 2013 1:42 pm
by Maryna Brodina

Please check checkbox name (it's case sensitive)


How to update multiple objects in a collection on a single click

Posted: Mon Aug 05, 2013 10:02 am
by vipul

Hi Marina
Checkbox name is correct, is there any property setting that i need to do for checkbox before running this script.


How to update multiple objects in a collection on a single click

Posted: Mon Aug 05, 2013 10:09 am
by Kateryna Grynko

Hi,

This should be working. Please give us a public link to your app.