I am using the JQuery Address plug-in to bookmark state changes in an
application. The application allows a user to run a search of a
document set. When the user requests a search that has not been run
before, the search is performed and then the search form and search
results are cached using data(), so that they can be retrieved later
if the user presses the back button.

All of the above is working fine except that the form values in the
form that is being cached are being lost. If I use bind() instead of
livequery(), the form values are retained. However, as I am re-
populating the form div with the cached form later, I cannot used bind
() or the event bindings are lost.

Here is the relevant code. Anyone have any ideas as to why this is
happening and how to fix it?

HTML
<div id="<portlet:namespace/>_cmlSearch_container">
<div id="<portlet:namespace/>_cmlSearch_msg" class="alert"
style="display: none;"></div>
<form action="<portlet:renderURL windowState="RAW"/>"
name="<portlet:namespace/>_cmlSearch_form" id="<portlet:namespace/
>_cmlSearch_form" method="post">
<input type="hidden" name="searchType" value="simplesearch">
<div id="<portlet:namespace/>_cmlSearch_simple">Keyword: <input
type="text" id="keyword" name="keyword" />&nbsp; <input
id="cmlSearch_submitBtnTop" type="submit" value="Search"/></div>
<br />
<a id="<portlet:namespace/>_cmlSearch_advancedSearchLink"
href="javascript:void(0)"><img src="<%=response.encodeURL
(request.getContextPath() + "/images/icon_plus.gif")%>"
name="<portlet:namespace/>_cmlSearch_advancedSearchLinkIcon"
id="<portlet:namespace/>_cmlSearch_advancedSearchLinkIcon" border="0"
alt="+" />&nbsp;Advanced Search</a>
<div id="<portlet:namespace/>_cmlSearch_advanced" style="display:
none;">
<table id="<portlet:namespace/>_cmlSearch_advancedSearchFields"
class="cmlAdvancedFieldsTable">
        <jsp:include page="cmlform.jsp"/>
</table>
<br />
<input id="cmlSearch_submitBtnBottom" type="submit" value="Search"/
>&nbsp;<input id="cmlSearch_clearBtnBottom" type="reset" value="Clear"/
>
</div>
</form>
<div id="<portlet:namespace/>_cmlSearch_loading" style="width: 300px;
margin-left: auto; margin-right: auto; text-align: center; display:
none;"><img src='/cml/images/ajaxLoader.gif'></div>
<div id="<portlet:namespace/>_cmlSearch_searchResults"></div>
</div>

jQuery(document).ready(function() {
var nsPrefix = "#<portlet:namespace/>_";
        jQuery(nsPrefix+"cmlSearch_form").livequery("submit", function(){
                var uId = new Date().getTime();
                var hash = "searchresults/<portlet:namespace/>/"+uId;
                jQuery.address.value(hash);
                return false;
        });
});

FROM jQuery.address.change(function(event){

var cachedContent = jQuery(nsPrefix+"cmlSearch_container").data(uId);
                //check the cache to see if this search was already run
                if(cachedContent == undefined){
                        //if not, do the search and cache the search container 
contents
                        var url2Call = 
jQuery(nsPrefix+"cmlSearch_form").attr("action");
                        var formData = 
jQuery(nsPrefix+"cmlSearch_form").serialize();
                        doSearch(url2Call, formData, ns, uId);
                }else{
                        //if yes, re-populate the search container with cached 
content
                        
jQuery(nsPrefix+"cmlSearch_container").html(cachedContent);
                }

FROM doSearch(url2Call, formData, ns, uId){

complete: function(xhr, textStatus){
                                jQuery(nsPrefix+"cmlSearch_loading").hide();
                                var content = 
jQuery(nsPrefix+"cmlSearch_container").html();
                                
jQuery(nsPrefix+"cmlSearch_container").data(uId,content);
                        }

Reply via email to