PDA

View Full Version : How to create a clear button using Jquery for refine search



rosegarden
July 29, 2012, 04:07 PM
I been doing this whole night and I still can't get this RESET button ... anyone?

How to create a Clear button to clear all the fields so that user can do a fresh refine search?


=========== refine_search.tpl ==================

<table>
<tr>
<td style="padding-{$text_dir_rev}: 10px;"><input class="search_field_item button" type="submit" name="search" value="{$lang.search}" /></td>
<td><input type="button" class="button" value="Clear Form" id="reset_filter_button" /></td>
</tr>
</table>


<script type="text/javascript">

{literal}

$(document).ready(function(){
$('#reset_filter_button').click(function(){
eraseCookie('listings_sc');
listingsGrid.reset();

$("#filters select option[value='']").attr('selected', true);
$("#filters input[type=text]").val('');
$("#Category_ID option").show();
});

{/literal}
</script>

Viktor
July 30, 2012, 06:43 AM
Hello Desmond,

Would you please create a new button with id="reset_filter_button" and insert next code in file.


<script type="text/javascript">
{literal}
$('#reset_filter_button').click(function(){
$(".refine").find("select").each(function(){
$(this).val('0');
})
$(".refine").find("input[type='text'], input[type='hidden']").each(function(){
$(this).val('');
})
});
{/literal}
</script>

rosegarden
July 31, 2012, 05:32 AM
I have tested it does not work well

Step 1:
Search field A
Press "Search

Step 2 :
Search result listing appear for field A

Step 3:
Press "Reset Search"
reset ... field A disappear on Refine search box

Step 4 :
Change field B
Press "Search"

Step 5:
Search result listing appear for field B
But on the refine search box, it show field A not B.

It did not clear the previous session completely. You can test it on my site to confirm my findings

Viktor
July 31, 2012, 08:22 AM
Hello Desmond Lim,

Yes you are right. I found problem. Please go to ftp:includes>>controllers>>listing_type.inc.php
find code:


/* emulation */
if ( $_SESSION[$listing_type_key .'_post'] && $_REQUEST['action'] != 'search' )


and replace to:


/* emulation */
if ( $_SESSION[$listing_type_key .'_post'] && $_REQUEST['action'] != 'search' && !$_POST )

rosegarden
August 2, 2012, 02:32 AM
Hi Viktor
Thanks for the fix, it is working now