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

How to map a distinct array of results from a column (field) to a list?

Hello! Please try the following code:
codevar data = arguments[0];
var dropDown = Appery("mobileselectmenuName");
dropDown.empty();
$.each(data, function(index, option) {
dropDown.append(
$('<option value="' + option + '">' + option + '<&#47;option>')
);
});
dropDown&#46;selectmenu("refresh");/code

Shaun Summers
Posts: 0
Joined: Thu Jul 25, 2013 3:49 pm

How to map a distinct array of results from a column (field) to a list?

That works. Thank you very much. I really appreciate the help.

Shaun Summers
Posts: 0
Joined: Thu Jul 25, 2013 3:49 pm

How to map a distinct array of results from a column (field) to a list?

For anybody picking up this thread. Here is the condensed version of what was done:

  • I initially create a new service (MySizeIn_Sizes_Distinct_List_Brands) to get the distinct values in a field from the appery database

  • I then added this service as a datasource to my page and named it “fill_brand_dropdown”

  • I noticed at this point that I had no field name available for mapping and opened this bug. Appery suggested the following as a work around:

  • I created the following Event on the data screen for my page:
    fill_brand_dropdown Success Run JavaScript

  • I then entered the javascript posted above by appery. Just changing the mobileselectmenuName to the name of my dropdown list in the design screen.

    This works. Thank you to Appery and I hope this helps somebody else.

Shaun Summers
Posts: 0
Joined: Thu Jul 25, 2013 3:49 pm

How to map a distinct array of results from a column (field) to a list?

Would anybody know how to add a placeholder into this code ie. 'Please select...' ?

The one for the component is getting overwritten by the javascript.

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

How to map a distinct array of results from a column (field) to a list?

Hi, not sure I understand what code you mean. Could you clarify please? If you want to post some code use < code tag.

Shaun Summers
Posts: 0
Joined: Thu Jul 25, 2013 3:49 pm

How to map a distinct array of results from a column (field) to a list?

Hi Marina,

The code that you kindly suggested:

code
var data = arguments[0];
var dropDown = Appery("mobileselectmenuName");
dropDown&#46;empty();
$&#46;each(data, function(index, option) {
dropDown&#46;append(
$('<option value="' + option + '">' + option + '<&#47;option>')
);
});
dropDown&#46;selectmenu("refresh");
/code

I'm just looking for a way to include a placeholder such as 'Please select...'.

Regards, Shaun

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

How to map a distinct array of results from a column (field) to a list?

You would need to add an option with attribute data-placeholder="true"
codevar data = arguments[0];
var dropDown = Appery("mobileselectmenuName");
dropDown&#46;empty();
dropDown&#46;append($('<option data-placeholder="true">Choose one&#46;&#46;&#46;<&#47;option>'));
$&#46;each(data, function(index, option) {
dropDown&#46;append(
$('<option value="' + option + '">' + option + '<&#47;option>')
);
});
dropDown&#46;selectmenu("refresh");/code

Shaun Summers
Posts: 0
Joined: Thu Jul 25, 2013 3:49 pm

How to map a distinct array of results from a column (field) to a list?

Wonderful! Thanks a lot. I appreciate that this question was not directly related to your product and it was very kind of you to help.

Return to “Issues”