Page 1 of 1

Getting Select Component Value AND Label

Posted: Wed Jul 08, 2015 11:48 pm
by Jack Bua

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?


Getting Select Component Value AND Label

Posted: Thu Jul 09, 2015 10:44 am
by Pavel Zarudniy

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


Getting Select Component Value AND Label

Posted: Thu Jul 09, 2015 6:46 pm
by Jack Bua

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


Getting Select Component Value AND Label

Posted: Thu Jul 09, 2015 6:53 pm
by Jack Bua

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?


Getting Select Component Value AND Label

Posted: Thu Jul 09, 2015 7:08 pm
by Jack Bua

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.


Getting Select Component Value AND Label

Posted: Fri Oct 30, 2015 1:28 pm
by David Lenz

Hi Jack,

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