Pete Gombert
Posts: 0
Joined: Tue Mar 18, 2014 2:42 pm

Populating a select menu with a value returned from the database

I am trying to populate a select control with the JSON results from a REST list service with one record. The select control has options which have been populated in the Appery user interface (rather than from the database). I have the proper field bound to the Selected attribute of the control, but when loaded the selection reflects the default rather than the item I am passing. I am using this form to Edit a user and their attributes.

Image

Here is a picture of the options I have entered: I tried using ID's to begin with but made them both text strings to simplify.

Image

Finally - here is a picture of the test interface. I added two labels and mapped the results to those as well, just to make sure I was returning the correct results. You can see from the picture that the fields are showing Monthly and Child and the Select controls are showing Daily and Parent.

Image

I know this must be simple and I am clearly doing something wrong, but none of the documentation I could find shows how to do this properly. Thanks

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Populating a select menu with a value returned from the database

Hello!
It's a bug, should be fixed in the next release (mid April). As a workaround in mapping to Selected property add the following JS pre$(element).val(value);/pre

Pete Gombert
Posts: 0
Joined: Tue Mar 18, 2014 2:42 pm

Populating a select menu with a value returned from the database

Got it. A couple of questions on the JS:

  1. Does the JS go in the select control's JS, or do I need to trigger it separately?

  2. If my control is named role_select and the JSON result field is role_ID would the JS be $("role_select").val('role_ID'); or do I need to set a local storage variable and then trigger the JS upon success of the service?

    Thanks for your help

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Populating a select menu with a value returned from the database

Add JS code in mapping, no need to change anything in code. Use it as posted above.

Pete Gombert
Posts: 0
Joined: Tue Mar 18, 2014 2:42 pm

Populating a select menu with a value returned from the database

Thanks! Finally this works - you are awesome! The bug is not awesome :-(

Return to “Issues”