Reputation: 4964
I have implemented a listview in my project (jQuery Mobile) and add a the textbox for the search.
But I want to show the listview first and only when the user clicks on the button to search open a textbox over the list.
Here is my code:
<a data-role="button" href="#" class="search">Show Search box</a>
<ul data-role="listview" data-filter="true" data-filter-placeholder="Pesquisa Contacto..." data-theme="d" data-divider-theme="d" style="padding:10px 10px 10px 10px;top:10px">
<li>
<a href="index.html">
<h3>jQuery Team</h3>
<p><strong>Boston Conference Planning</strong></p>
<p>In preparation for the upcoming conference in Boston, we need to start gathering a list of sponsors and speakers.</p>
<p class="ui-li-aside"><strong>9:18</strong>AM</p>
</a>
</li>
</ul>
JAVASCRIPT:
$(document).on('pagebeforeshow', '#p33', function () {
$('form.ui-listview-filter').hide();
});
$(document).on('click', '.search', function () {
$('form.ui-listview-filter').show();
});
Upvotes: 3
Views: 3082
Reputation: 31732
Hide Search box.
$(document).on('pagebeforeshow', '#pageID', function () {
$('form.ui-listview-filter').hide();
});
Show it on button click. The button has class search
.
$(document).on('click', '.search', function () {
$('form.ui-listview-filter').show();
});
Upvotes: 4
Reputation: 2926
One way is - Have the Mark up as-
<form id ="searchForm"class="ui-listview-filter ui-bar-c" role="search" style="display:none;"><div class="ui-input-search ui-shadow-inset ui-btn-corner-all ui-btn-shadow ui-icon-searchfield ui-body-c"><input placeholder="Filter items..." data-type="search" class="ui-input-text ui-body-c"><span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">clear text</span><span class="ui-icon ui-icon-delete ui-icon-shadow"> </span></span></a></div></form>
<ul data-role="listview" data-filter="true" data-filter-placeholder="Pesquisa Contacto..." data-theme="d" data-divider-theme="d"
style="padding:10px 10px 10px 10px;top:10px">
<li><a href="index.html">
<h3>jQuery Team</h3>
<p><strong>Boston Conference Planning</strong></p>
<p>In preparation for the upcoming conference in Boston, we need to start gathering a list of sponsors and speakers.</p>
<p class="ui-li-aside"><strong>9:18</strong>AM</p>
</a></li>
</ul>
Note that <form>
has style="display:none;"
as inline css
.
Now, unhide/hide the Search form on the button click action- something like-
$(document).on("click","#BUTTON-SELECTOR",function(){
$("searchForm").toggle();
});
Upvotes: 3