kosbou
kosbou

Reputation: 3999

jQuery Mobile Pagebeforeshow and longlist selectmenu

I use JQuery mobile 1.0.1.

I create a page with the below code

<div data-role="page" id="homecomments">
   <div data-role="header">
      <h1>Comments</h1>
      <a href='#home' class='ui-btn-left' data-icon='home' data-theme="a" data-iconpos="notext">Home</a>
   </div>
   <div data-role="content">
      <select name="building" id="opt1" data-native-menu="false">
         <option>building</option>
      </select>
   </div>
</div>

And I call the page with

$('#homecomments').live('pagebeforeshow', function() {
   getTitlesComments()
});

and

$( document ).delegate("#homecomments", "pagecreate", function() {
   $("#opt1").change( function() {
   if ($( "#opt1 option:selected" ).val() != 0) {
      ====================DO SOMETHING=======================
   }
});

and

function getTitlesComments() {
   $('#opt1').val('');
   $("#opt1").selectmenu('refresh');
   ==========dynimicaly create longlist selectmenu opt1========
}

I have to use a long list in select menu. Every time I make a selection from the long list the selectmenu is reseted.

How can I solve this??

Upvotes: 0

Views: 137

Answers (1)

Jim Eisenhauer
Jim Eisenhauer

Reputation: 11

The long-list select is "hiding" the page, so when you are going back after making selections it is again "showing" it. The good news is it is still keeping your selection(s). You can check for their existence in your pagebeforeshow code and select the values as your code creates the options list again.

$("#opt1").selectedValues().join(",");

Will give you a comma separated list to work with.

Upvotes: 1

Related Questions