Why are my fields not populating based on the encoded search query I'm passing it?
I've got a nice convoluted workflow going here, but I think it should still work. This may come down to a parsing order.
First I have the search page https://centralsc.org/regionaldata/pr...
The main section of the page with all the properties listed is loaded via ajax. What I'm adding (which is on a dev site not that live site) is the ability to store a search in the users cookies, so that if they navigate away from the search page, when they return it will load in their last search rather than resetting the search back to all properties.
The template that is called via ajax has a low_search:results tag in it which generates my results based on the encoded query I send it via a segment in the GET request url. That encoded query is also stored into a cookie. (For what it's worth, if the cookie is not set I my GET Request url has fewer segments and thus it knows to return all results using a stand channel:entries tag that's in there).
When the main property search page (the one linked above) is first loaded or refreshed, it checks to see if that cookie is set, if it is, then it feeds that to my low_search:form tag as well as makes the initial ajax call sending that encoded query to the results template just as it would if I submitted the form.
So far, this works great.
What I need to do now is automatically fill in the form based on the encoded search query. This part does not work so well, or at all. Here's an abbreviated version of what I'm trying to accomplish just using the first input box:
{exp:low_search:form form_id="property_filter" form_class="property-search" query="{exp:dwg_centralsc:cookieValue cookie-name='csc_property_search'}" }
Site/Building Name
{/exp:low_search:form}
dwg_centralsc:cookieValue is a custom plugin I have that returns the value of that cookie. Basically I'm not getting a value. In fact when I inspect the field, there isn't even a blank value attribute, it's as if {low_search_search:name} is null. I'm wondering if my plugin is getting parsed after the form tag, thus not passing it the query? Otherwise it returns the string just fine when I log it to the console via the console.log that you see there.
If I simply echo out {low_search_search:name} in my results template, it shows up just fine so I would assume that's the correct syntax here. Am I missing something?
thanks for any help.
Replies
Low 26 May 2016 07:31
If you're using a tag as input for another tag's parameter, you'll need to add parse="inward" to the outer tag. So try adding that to the Form or Results tag.
You can also try and enable template debugging to see what the actual value of the parameter is.
Andy McCormick 26 May 2016 12:32
@Low . Thanks. That got me on the right track. I got it working through a combination of issues that were all happening at once.
First my plugin tag wasn't being parsed even with parse="inward", template debugging still showed it as the tag not parsed, though it was being parsed after the form as shown by the console.log.
So then I add a preload_replace variable, setting that variable to the output of my
plugin tag. I tried this before and it hadn't worked but I noticed that I had strtolower in my plugin because I'm using the same plugin function elsewhere. So I had to add the option to decide if it would return lowercase or not.
This still wasn't working in the form query param though. So then I added parse="inward" back to the form tag and it works perfectly!
So here's what I ended up with