M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Have default value of a select menu come from the database have have other options listed.

your default value is "default" whereas it should have your default value unless your default really means the word "default"

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

Have default value of a select menu come from the database have have other options listed.

My default value depends on what a user has saved in the database.

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Have default value of a select menu come from the database have have other options listed.

So after populating the component with value from the database, fetch the default value the user saved in the database and then set the value of the component to the default value you retrieved from the database

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Have default value of a select menu come from the database have have other options listed.

Assuming that you retrieved the default value the user had previously saved into a variable called "PreviouslySelectedValue". Then your code to set the default value of the select component will be (Assuming that you already populated the select component).

If you had saved the previously saved value in a local storage variable you can retrieve it with

var PreviouslySelectedValue = localStorage.getItem('lsvPrevSelection');

// Change "SelectComponentName" accordingly

var selectComponent = Appery("SelectComponentName");
selectComponent.val(PreviouslySelectedValue);
selectComponent.selectmenu('refresh', true);

Btw you may want to confirm that the default value does exist in the select list before setting the default

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

Have default value of a select menu come from the database have have other options listed.

Now in the select menu, it doesn't show anything as the default. It is blank and if you click it, you will then see options.

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Have default value of a select menu come from the database have have other options listed.

Do this -

// Change "SelectComponentName" accordingly

var selectComponent = Appery("SelectComponentName");
selectComponent.val("HARD_CODE_ANY_EXISTING_VALUE_HERE");
selectComponent.selectmenu('refresh', true);

What the above does is to use a known / hard- coded value. Check if this results in a value being selected?

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

Have default value of a select menu come from the database have have other options listed.

So using that code, it works almost right. After I use the select menu to update that field, it switches back to the value that it was before. Then if I just tap the select menu then tap away to close it without selecting any other value, it will refresh and show the correct value. How can I fix this?

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Have default value of a select menu come from the database have have other options listed.

Hello Ellen!

1) Please try to move that code on page show event.
or please note
2) After your mapping is done, new values will not remove it
or
3) If value are hardcoded, you can add this value in the editor

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

Have default value of a select menu come from the database have have other options listed.

I only understood the first but when I tried it, it didn't work.

Return to “Issues”