w
Posts: 0
Joined: Tue Mar 26, 2013 12:30 pm

add an option with an empty value attribute to a selectmenu

When I create a selectmenu, for example with 1 option like this:

precode
List.empty();
List&#46;append('<option value="">Testoption<&#47;option>');
/code/pre

Shows this in HTML: , and the option is not shown in the list.:

precode
<option value="" data-placeholder="true">Favorieten<&#47;option>
/code/pre

When I create exactly the same, but with something in the value attribute:

precode
List&#46;empty();
List&#46;append('<option value="test">Testoption<&#47;option>');
/code/pre

I get the correct HTML and the option is visible in the list:

precode
<option value="test">Favorieten<&#47;option>
/code/pre

What do I have to do if I want an option with an empty value? Because my database returns sometimes empty strings, which are placed in the value attribute.
And I don't want to change the empty string into something else, because I want the selectmenu.val() to be the empty string when the option with the empty value is selected.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

add an option with an empty value attribute to a selectmenu

Are you simply using jQuery Mobile API to create the list?

w
Posts: 0
Joined: Tue Mar 26, 2013 12:30 pm

add an option with an empty value attribute to a selectmenu

The list, named "List", is put in the UI with Appery.

Then on the page show event, the code from the post above is executed.

I also do a List.selectmenu('refresh', true).trigger('change'); afterwards.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

add an option with an empty value attribute to a selectmenu

It's normal behavior for select:
http://jquerymobile.com/demos/1.2.0-b... (see Placeholder options)

To change this behavior you can create new JS file with this code
$.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false;

Return to “Issues”