Page 1 of 1

concatenate two fields from a service to use is in a selectbox label

Posted: Wed Oct 23, 2013 3:22 pm
by michaelsperber01

Hi

Can anyone tell me how to concatenate two fields from a service to use is in a label?
I have two fields coming from a service that i linked to a option in a selectbox. The two fields should be concatenated, but i can't find how. So far i have linked the fields to the options label, then i open Add JS. my guess is that the code should be
return field1 + " " + field2;
but that seems to be wrong.


concatenate two fields from a service to use is in a selectbox label

Posted: Wed Oct 23, 2013 3:53 pm
by maxkatz

You can use this approach: http://docs.appery.io/documentation/u...


concatenate two fields from a service to use is in a selectbox label

Posted: Wed Oct 23, 2013 5:21 pm
by michaelsperber01

Thanks, Max that helped somewhat, but i'm not sure how to do this in a "loop"

The example uses Appery("addressLabel") to address the right field to put the content in, but in my case this is a loop through the returned records, populating the options in the select box. So that should be like: Appery("addressLabel" + i) or something to address the current option. How should i target the label of the option that is currently being added to the selectbox?


concatenate two fields from a service to use is in a selectbox label

Posted: Wed Oct 23, 2013 6:49 pm
by Kateryna Grynko

Hi Michael,

You can use the following JS code:prereturn $(element).attr("value") + value;/pre


concatenate two fields from a service to use is in a selectbox label

Posted: Wed Oct 23, 2013 7:02 pm
by michaelsperber01

Hi Katya

I don't quite understand what you did there, but it works!
It has some unexpected side effect, if i do:
return $(element).attr("value") + value + " visitors";
the resulting label has " visitors" pasted after the first and after the second 'value'.
which makes me realize i don't really understand how this works.
thanks for your help!


concatenate two fields from a service to use is in a selectbox label

Posted: Wed Oct 23, 2013 8:19 pm
by Kateryna Grynko

Michael,

When you add this code to a component mapped to 2 response fields then it fires twice.

The easiest way to add "visitors" in the end of final string is to do this after executing service.

For example, on service Complete event run the following JavaScript code:prevar options = Appery("mobileselectmenu_47").find("option");
options.each(function(e) {
if (e 0)
$(options[e]).attr("value", $(options[e]).attr("value") + "visitors");
});/pre


concatenate two fields from a service to use is in a selectbox label

Posted: Thu Oct 24, 2013 8:35 am
by michaelsperber01

Thanks very much Katya, I understand now!