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

Unable to set SELECTED value of SELECT component from database

Hello,
I try to set the SELECTED value of SELECT component by reading it from the Appery database.

My mapping looks like this:

Image

So you can see the DEFAULT PORTION WEIGHT database column being mapped to SELECTED value of my select component.

Unfortunately SELECT component stayed empty.

What I tried next was to refresh it during mapping by this JS:

Image

and then after successful service execution:

Image

but still my SELECT component is empty (blue rounded rectangle):

Image

My app is shared with APPERY support and is called 3MC.

Steps to reproduce:
1) Open the app.
2) Type "sapiens" into search box.
3) See the SELECT component without any selection made.

Please give me some hints how to fix this.

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

Unable to set SELECTED value of SELECT component from database

Hello,

According to your screenshots you set it's value multible times. Please set it only once, e.g. on the success event of the service with a JS code like:
preApperyio("mySelectmenu").val("Vidi").trigger("change");/pre
here mySelectmenu - name of the select component

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

Unable to set SELECTED value of SELECT component from database

Hello Sergey. Thanks for your response but I suspect you might have not understood the app logic. Yes I set it multiple times because each list item has separate SELECT component which has its own default value read from database. Could you please look again more closely at the logic behind my scenario?

Just to make sure you get the business case right:

1) in my database I have like 1.800 food articles.
2) each article can have multiple options of packaging (like BAG, SPOON, BOOTLE, GLASS, PIECE etc) with different weights.
3) only one packaging option is a default one and I need to read it from DB and put into SELECT component for each article.

Just to give you an example. In case of HAMBURGER user will have only one option like PIECE with 300g of default weight. But in case of SUGAR he will have a SPOON, GLASS or BAG with weights like 10g, 200g or 500g. The default option would be SPOON.

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

Unable to set SELECTED value of SELECT component from database

It is hard to set selected value and add all options with only one mapping. Please use 2 mappings, which work one-by-one:
1) Generate select options
2) Set default option for each select component

Another way to do that is: set the first option of each select component selected by default

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

Unable to set SELECTED value of SELECT component from database

Hi Sergiey. That looked promising and I have followed your advice. Now I have two separate mappings (on success) which:

1) populate select menu options (1st mapping)
2) set default value (2nd mapping)

Additionally as I expect that selectmenu component needs refreshing after changing value via JS I have attached following code after successful 2nd mapping:

$(document).find("[name='PortionTypeSelect']").selectmenu();
$(document).find("[name='PortionTypeSelect']").val("").selectmenu('refresh');

Unfortunately I still receive empty selectmenu - no default option is selected.
Could you please take look at it?

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

Unable to set SELECTED value of SELECT component from database

That JS line does nothing:
$(document).find("[name*='PortionTypeSelect']").selectmenu();

This JS line set's emty value by default:

$(document).find("[name*='PortionTypeSelect']").val("").selectmenu('refresh');

Please show us mapping of the setting select value by- default and JS code, which you use in that mapping

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

Unable to set SELECTED value of SELECT component from database

Without the first line I get the error stating that I attempt to refresh select without prior initializing it...

The mapping is as follows:

Image

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

Unable to set SELECTED value of SELECT component from database

Please share (http://devcenter.appery.io/documentat...) your app with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a and provide us with the following information:

1) App name
2) Test credentials if login functionality is implemented in your app
3) Detailed steps to reproduce the issue

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

Unable to set SELECTED value of SELECT component from database

Siergy, all info you requested is in the first post above, and app is shared with Appery support.

Once you type SAPIENS and get the search results in order to see the SELECT COMPONENT you have to mark the checkbook "Użyj porch standardowej":

Image

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

Unable to set SELECTED value of SELECT component from database

Sorry, but your service returns DefaultPortionWeight=23:

Image

But there are no such option in the PortionTypeSelect component:
Image

It must have that value to make it selected by default

Return to “Issues”