Brian Evans
Posts: 0
Joined: Mon Feb 03, 2014 9:28 pm

Dynamic select menu selected item from REST

Dynamic select menu not selecting proper value from repose. Response from service call I populate a select menu and which should be selected as well from same response. HTML produced is looking like

and option isn't being selected.

Col.

I have all the mappings properly.

Brian Evans
Posts: 0
Joined: Mon Feb 03, 2014 9:28 pm

Dynamic select menu selected item from REST

code
<select name="prefix" value="Col&#46;">

<option value="Col&#46;">Col&#46;</option>
/code

Brian Evans
Posts: 0
Joined: Mon Feb 03, 2014 9:28 pm

Dynamic select menu selected item from REST

This is the HTML produced, forgot the code tags.

code
<select name="prefix" value="Col&#46;">
<option value="Optional" selected="selected">Optional</option>
<option value="Col&#46;">Col&#46;</option>
</select>
/code

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Dynamic select menu selected item from REST

Hi Brian,

Not sure I've understand you correctly - do you want to set attribute "selected" using the service?

Are you using component 'select':
http://docs.appery.io/documentation/u...

Brian Evans
Posts: 0
Joined: Mon Feb 03, 2014 9:28 pm

Dynamic select menu selected item from REST

Using select component that's options are populated from a REST call. That same rest call also has which item should be selected. It's not being set properly instead the select component generates.

code
<select name="prefix" value="Col&#46;">
<option value="Optional" selected="selected">Optional</option>
<option value="Col&#46;">Col&#46;</option>
</select>
/code

instead of what I would expect would be.

code
<select name="prefix" value="Col&#46;">
<option value="Optional">Optional</option>
<option value="Col&#46;" selected="selected">Col&#46;</option>
</select>
/code

Brian Evans
Posts: 0
Joined: Mon Feb 03, 2014 9:28 pm

Dynamic select menu selected item from REST

On success of the REST call adding this JS seems to do the trick.

code
var prefix = response&#46;Contact["prefix"];
$('[name=prefix] option[value="'+prefix+'"]')&#46;attr("selected", "selected");
$('[name=prefix]')&#46;selectmenu('refresh');
/code

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Dynamic select menu selected item from REST

Brian,

Please check what you store in prefix variable, seems it's "Optional" there..

Also it's better to use the next code to set the value:
pre
Appery("prefix")&#46;val(prefix )&#46;selectmenu('refresh');/pre.

Oscar
Posts: 0
Joined: Tue Jun 03, 2014 8:22 pm

Dynamic select menu selected item from REST

Hi Alena,

I have a Select component named "iGrup" with several options with values numbered from 1 to 9. I want to select one of that options with the response of a REST. In this response I have the number, for example 5 and I want to show selected the option with value 5. How can i do that?

I linked the response to the Select component and the link is did it with Visible attribute of the Select component. I add sombe JS to the response:

Appery("iGrup").val(value).selectmenu('refresh');

Please help me.

By the way, where can i find usefull "Appery" JS API documentation, because the documentation in appery.io web is ridiculous ;-)

Thanks in advance.

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

Dynamic select menu selected item from REST

Hello,

This code should work we have just tested it:

codeApperyio("mobileselectmenu_14")&#46;val("2")&#46;selectmenu('refresh'); /code

Try checking mapping of your service to select component.
Every app you create in Appery.io includes jQuery, jQuery Mobile and Apache Cordova (PhoneGap) libraries. Please visit each site to learn what methods/properties/APIs are available.

Oscar
Posts: 0
Joined: Tue Jun 03, 2014 8:22 pm

Dynamic select menu selected item from REST

Works finally, thank you.

Return to “Issues”