Jack Bua
Posts: 0
Joined: Sun Jun 28, 2015 10:16 pm

Getting Select Component Value AND Label

I want to put the value of the selected item in one field in a collection and the label in another.

Image

My mapping

Image
The JS code was a refresh of the component that did not help.

The above mapping transfers the value correctly, but just the first label in the list transfers.

For testing, I used JS to place the value of the select component's selected item into an input. That worked fine.

var one = Appery("task_select").val();
Appery("testinput").val(one);

But I got something dd when I tried to do the same for the labels:

var one = Appery("task_select").text();
Appery("testinput").val(one);

returned : " Select Task... Design Sample Procurement Delivery Setup Demolition Removal Repairs Prep Build " which happens to be all of the labels, regardless of which item is selected.

Any suggestions?

Pavel Zarudniy
Posts: 0
Joined: Mon Jul 06, 2015 8:56 am

Getting Select Component Value AND Label

Hi Jack,
Use code like this to get label:
code
var one = Appery("task_select").find('option:selected').text();
Appery("testinput").val(one);
/code

Jack Bua
Posts: 0
Joined: Sun Jun 28, 2015 10:16 pm

Getting Select Component Value AND Label

Thank you for your reply Pavel. How would I map that?

Jack Bua
Posts: 0
Joined: Sun Jun 28, 2015 10:16 pm

Getting Select Component Value AND Label

This code gets the label to send in the mapping.

var one = Appery("task_select").find('option:selected').text();
return one;

but there is a lot of spaces before and after the text.

" Demolition "

Any way to fix this?

Jack Bua
Posts: 0
Joined: Sun Jun 28, 2015 10:16 pm

Getting Select Component Value AND Label

I'm condensing my previous responses into this one. The solution to my problem as to how to map a select component's selected item's label to a collection field is this:

On the mapping from the page to storage, map the select button's label value to the desired field in the collection and place this JS on it:

var lbl = Appery("select_menu").find('option:selected').text();
lbl = lbl.trim();
return lbl;

where select_menu is the name of your select component and lbl is whatever you want to name your variable. The trim method takes away spaces before and after the label.

Hope this helps someone else and I thank Pavel for setting me on the right path.

David Lenz
Posts: 0
Joined: Fri Oct 30, 2015 1:28 pm

Getting Select Component Value AND Label

Hi Jack,

thank you, your suggested code works just fine for me!

Return to “Issues”