Page 1 of 1

Set checkbox item selected if value is found in array returned from a Parse.com REST response

Posted: Tue Jul 15, 2014 10:47 pm
by tiggziuser

I have a Parse.com database class that has an array column. The array column contains multiple userIDs.

I have a REST query that maps to a checkbox group that lists all the rows in the class. I want to set each checkbox selected or unselected based on whether or not the stored local storage variable is found within the array column for each row.

How can I do this with out having to make Parse queries for each checkbox item?


Set checkbox item selected if value is found in array returned from a Parse.com REST response

Posted: Wed Jul 16, 2014 4:08 am
by Yurii Orishchuk

Hello,

Please use following JS code for "add js" mapping: http://prntscr.com/43535k/direct

pre

var lsvName = value;
var currentItemChecked = localStorage.getItem(lsvName);

var isChecked = currentItemChecked == "true";

element.find('input[type="checkbox"]').prop("checked", isChecked);

return value;

/pre

Also this solution require:

If you have item with text "hello" you need to have LSV with name "hello" and value for checked - should be "true" and not "true" for not checked.

Regards.


Set checkbox item selected if value is found in array returned from a Parse.com REST response

Posted: Thu Jul 17, 2014 5:05 am
by tiggziuser

Hmmm. What about finding the item I need in each array I receive from the response array?? I added an image of my data mapping.Hope it makes things more clear.
Image


Set checkbox item selected if value is found in array returned from a Parse.com REST response

Posted: Thu Jul 17, 2014 7:36 pm
by Kateryna Grynko

Hi,

Could you clarify please whether you mean to find an appropriate ObjectId for each record in 'favorites' array?
Add the following code to mapping results[]-mobilecheckbox:
preif (jQuery.inArray( value.ObjectId, value.favorites )){
alert("found");
}/pre


Set checkbox item selected if value is found in array returned from a Parse.com REST response

Posted: Fri Jul 18, 2014 1:32 am
by tiggziuser

Found that jQuery function today. I wasn't sure if the javascript ran on every iteration but now I know. I need to search for a localstorage variable in the favorites array that is returned from the response. If found set the checkbox selected.

Here is what I have,

var userID = localStorage.getItem("CurrentUserID");

if (jQuery.inArray( userID, value.favorites )){

Code: Select all

 Appery("checkboxTopic").prop('checked', true); 

}

I tried adding that to the results[]-mobilecheckbox mapping but nothing gets checked. Is the Appery call incorrect?


Set checkbox item selected if value is found in array returned from a Parse.com REST response

Posted: Fri Jul 18, 2014 2:56 am
by Yurii Orishchuk

Hi,

You need to modify your code with following:

pre

var userID = localStorage.getItem("CurrentUserID");

if (jQuery.inArray( userID, value.favorites )){

Code: Select all

 //Open your browser to see what items ready should be marked with checkbox. 
 console.log("checked value = " + userID); 

 //This will find input checkbox component and set checked property to true. 
 element.find('input[type="checkbox"]').prop('checked', true); 

}

/pre

Regards.