Page 1 of 2

Dynamic select menu selected item from REST

Posted: Thu Feb 27, 2014 3:57 pm
by Brian Evans

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.


Dynamic select menu selected item from REST

Posted: Thu Feb 27, 2014 3:59 pm
by Brian Evans

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

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


Dynamic select menu selected item from REST

Posted: Thu Feb 27, 2014 4:01 pm
by Brian Evans

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


Dynamic select menu selected item from REST

Posted: Thu Feb 27, 2014 4:16 pm
by Illya Stepanov

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...


Dynamic select menu selected item from REST

Posted: Thu Feb 27, 2014 4:19 pm
by Brian Evans

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


Dynamic select menu selected item from REST

Posted: Thu Feb 27, 2014 5:19 pm
by Brian Evans

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


Dynamic select menu selected item from REST

Posted: Thu Feb 27, 2014 7:18 pm
by Alena Prykhodko

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.


Dynamic select menu selected item from REST

Posted: Tue Jun 03, 2014 8:22 pm
by Oscar

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.


Dynamic select menu selected item from REST

Posted: Wed Jun 04, 2014 8:54 am
by Evgene Karachevtsev

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.


Dynamic select menu selected item from REST

Posted: Wed Jun 04, 2014 9:09 pm
by Oscar

Works finally, thank you.