Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

Unable to set SELECTED value of SELECT component from database

Sorry Sergiy but according to what I know it does not work that way. What you see when you click on SELECT COMPONENT are only labels. Each label has a value assigned via mapping here:

Image

here you have the array read from PORTION ARRAY in DB :

[{"PortionTypeName":"szklanka","PortionWeight":"234"},{"PortionTypeName":"puszka","PortionWeight":"23"},{"PortionTypeName":"torebka","PortionWeight":"10"},{"PortionTypeName":"szklanka","PortionWeight":"33"}]

So basically setting the default value "23" should result in setting second option named "puszka" but instead i get empty selection.

Can you pleas investigate the issue further?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Unable to set SELECTED value of SELECT component from database

Please add JS code below to the success event of the Art_table_query service:

preApperyio("PortionTypeSelect").val(data[0].DefaultPortionWeight).selectmenu( "refresh" );/pre

Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

Unable to set SELECTED value of SELECT component from database

Sergiy you are a magician :) Thanks a lot, it works!!! The second mapping is not necessary, it works fine with single one.

Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

Unable to set SELECTED value of SELECT component from database

Hello Siergy. In fact I do have one problem with this solution. It looks like it is able to map values correctly only once. When you have more than one item returned by the service then only one gets correct mapping and value selected. The other one gets empty selection. To reproduce please follow this procedure:
1) type SAPIENS into search box
2) you will get two items in results and only SAPIENS TEST has valid selection.

If you type SAPIENS HOMO then you will get only one item with valid selection.

Can you please look one more time? In the meantime I have added back the second mapping you recommended but it has not changed anything.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Unable to set SELECTED value of SELECT component from database

Please set an attribute "data-id" to each PortionTypeSelect component and use jQuery selector: $("[name=PortionTypeSelect]") to get all PortionTypeSelect components.
And set their values, according to that attribute.

Unfortunately this is something outside the scope of standard Appery.io platform support. You may consider purchasing Advisory Pack to get more in-depth help on this question. Here is more information about Advisory Pack (http://appery.io/services/#Advisory_Pack).

Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

Unable to set SELECTED value of SELECT component from database

Hi Sergiy
First of all thank you for your tip. I am grateful for that because basing on that I was able to solve this problem.

To anyone struggling with similar issue please follow this route:

1) Put here:

Image

this code :

element.find("[name*='PortionTypeSelect']").attr("data-portionweight-value", value.DefaultPortionWeight); // default weight assigned to weight selector

Remember to put it into iteration mapping so the one with $. In that way each SELECT element will get its value read from service and assigned as an attribute. Of course you have to change names of your object and attribute accordingly.

2) Add this JS in the service success event:

Image

Remember to change object names and attributes !!! (mine was 'PortionTypeSelect').

What is more Sergiy I do not agree fully that this is outside Appery support scope, because:

Fact 1 - Mapping is supposed to be easy drag&drop job done via your visual editor. This is supposed to speed up your coding and app development.
Fact 2 - You can connect service response to pass db values to any components on the page.
Fact 3 - SELECT component has a property called SELECTED.
Fact 4 - You can drag any field from your service response and connect it to SELECTED property of SELECT component.
Fact 5 - You can expect that after doing so the SELECT will display the value you have assigned to it.
Fact 6 - Doing so FAILS and you do not get the intuitive and expected result.

So I would think about the possibility to set the order in which the mapping sequence is executed. In that way you would be able to decide that mapping sequence responsible for filling up the SELECT component would be executed first and the mapping sequence responsible for setting its value would be executed second. Your approach in which you advised to do two separate mappings and run them one after another is perfectly right except that in this case will not work since the second mapping overrides all other fields and actions done in the first one. So it all has to be done in one mapping, only the execution sequence has to be in some cases different.

Return to “Issues”