Page 2 of 3

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

Posted: Tue Jan 27, 2015 3:39 am
by M&M

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


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

Posted: Tue Jan 27, 2015 3:47 am
by Ellen Schlechter

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


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

Posted: Tue Jan 27, 2015 3:52 am
by M&M

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


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

Posted: Tue Jan 27, 2015 4:04 am
by Ellen Schlechter

I'm sorry but how do I do that?


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

Posted: Tue Jan 27, 2015 4:21 am
by M&M

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


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

Posted: Wed Jan 28, 2015 5:31 am
by Ellen Schlechter

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.


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

Posted: Wed Jan 28, 2015 6:56 am
by M&M

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?


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

Posted: Fri Jan 30, 2015 5:24 am
by Ellen Schlechter

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?


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

Posted: Mon Feb 02, 2015 7:38 am
by Evgene Karachevtsev

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


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

Posted: Mon Feb 02, 2015 2:44 pm
by Ellen Schlechter

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