Filter WebDrawer Search Forms
Lets say you have designed multiple search forms which are used via WebDrawer. These forms provide different fields with which to search. In addition to this you may also want to filter the results for each form to make them appropriate for the target audience.
Embedding the filter
One approach is to embed a filter based on the search form name. I did this by:
- editing Views\Search.cshhtml
- enable 'Name' retrieval for the search form
- add a filter field based on the name.
Name retrieval
Near the top of Search.cshtml you will see code that looks like this
searchForm = TrimHelper.Search<SearchForm>( BaseObjectTypes.SearchForm, "all", properties: new string[] { "ObjectType", "DefinitionForm" }).FirstOrDefault();
Add the property 'Name' in the propert list, so that it now looks like this:
searchForm = TrimHelper.Search<SearchForm>( BaseObjectTypes.SearchForm, sfName, properties: new string[] { "ObjectType", "DefinitionForm", "Name" }).FirstOrDefault();<p>Hello, World!
Add the filter
Further down the page is found the search form itself, starting with this HTML:
<form id="search-form-form" class="form-horizontal search-form" action="FormSearch" method="GET">
After this line add some code to insert a filter INPUT element, potentially different for each search form. The code below add a filter for the search form named 'Test Form'
@if (searchForm.Name == "Test Form") { <input type="hidden" name="filter" value="recType:Document" /> }
Warning
This is a convenience, not a security measure. For example a user could still modify the URL resulting from this search to avoid the filtering.