Mark Bowen
Posts: 0
Joined: Fri Feb 21, 2014 11:13 pm

Checkbox list data from multiple fields

I have a checkbox list (itemGroup) that is generated from a database following the excellent tutorials on the website. The text is displayed via a label (itemList).

I have a button that when activated collects the value of the checked boxes using this code:

$("input[type=checkbox]:checked").each(function() {
selected.push($(this).val());
});

This works an builds an array

I am now trying to return the value of other (non-visible) labels within the check box that have been returned from the database - essentially following the instructions used for the list item in this tutorial (the data is there - when I tick visible it works)
http://docs.appery.io/tutorials/build...

How do I obtain this information?

I have tried collecting this information in the loop above by constructing a second array that contains
Appery('consent').text());
(where consent is the name of the label). However it only returns the value of 'consent' from the first entry that was retrieved from the database. Any help in collecting this information would be appreciated.

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

Checkbox list data from multiple fields

Hello Mark,

If you retrieve data from DB, then you should save it directly from a service. It will be available on the service's success event, the service's response will be available in the data variable.

Mark Bowen
Posts: 0
Joined: Fri Feb 21, 2014 11:13 pm

Checkbox list data from multiple fields

Thanks, I am not sure what you mean by this - I want to return only the data that relate to the checked item - so in the example you have I would have the following information in the database
Id: ID string
Title : Apple
Description : Hard fruit

Id : ID string
Title: : Orange
Description : Citrus fruit

Id: ID string
Title : Banana
Description : soft fruit

I then have titles mapped to the 'title' label and the 'value' item that is part of the checkbox and description mapped to a hidden 'description' label item

The user selects the items and I want to be able to use both the title and the description so if the user selected banana and apple the app could display 'Apple is hard fruit. Banana is soft fruit'

So I think I have mapped the information correctly - but how do I retrieve only the selected part?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Checkbox list data from multiple fields

Hello!

To select all checkboxes try to find all parent elements (those ones which contain necessary labels), then find labels you need and retrieve their values. This should help http://api.jquery.com/category/traver...

Mark Bowen
Posts: 0
Joined: Fri Feb 21, 2014 11:13 pm

Checkbox list data from multiple fields

I used this and it returns a string of all the labels

var allWords = $(this).siblings().text();

I just need to work out how to split this into individual strings now (?paragraphs)

Thank you so much for your help

Mark

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

Checkbox list data from multiple fields

Hi Mark!

You can save these values to array arr like this:

var arr = new Array();
Appery("mobilecheckbox").siblings().each(function(){
arr.push($(this).text());
});

where mobilecheckbox is the name of checkbox component

Return to “Issues”