Gerrit Oertel
posted this on April 28, 2009 14:54
<search field="description" exact="false"></search>
Add searching capabilities to the display view on a board.
In versions 7.2 and later, this tag has been modified to be more flexible, to allow searching across multiple fields, to allow multiple search tags to be used, and to search over ranges, such as a date range. If multiple search tags are used, the criteria are “ANDed” together, meaning the criteria from all of the active search tags must be met, as opposed to any of the criteria.
In addition to the attributes above (field, exact), the following attributes and tags can be used.
Example:
<search field="description" exact="false">
<field name="Priority"/><field name="Name"/><field name="Status"/>
</search>
<clearsearchbutton/>
<search field="description" showclear="true" />Or
<search field="description" /><clearsearchbutton />cleartext – This is the text that will appear on the clear button. The default text is set to “Clear.”
Comments
Is there a way to search multiple fields at once? I have a board that lists an entry's first and last name separately, and I would like to search both fields at once.
So a search for 'Pete' would show both Peter Whipple and Dave Peterson.
Mike Weber
Here's a workaround I did, to search multiple fields:
1. Add a hidden field on the input view. In this example, the field is a textarea called SearchText:
<textarea name="SearchText" rows="4" cols="60" style="display:none;"></textarea>
2. Add the following javascript in the input view html. The field names in the runWhenSubmitted function will need to be modified for your particular fields. In this example, the board is a contact information directory. All of the fields (first name, last name, phone numbers, etc.) are put into one string variable called strText. strText is then placed into the SearchText field. This technique can be found in the Scriptaculous section of webeoc.com.
<script type="text/javascript">
function runWhenSubmitted()
{
var strText = document.forms[0].LastName.value + " ";
strText += document.forms[0].FirstName.value + " ";
strText += document.forms[0].Title.value + " ";
strText += document.forms[0].Entity.value + " ";
strText += document.forms[0].Department.value + " ";
strText += document.forms[0].Division.value + " ";
strText += document.forms[0].OfficePhonePrimary.value + " ";
strText += document.forms[0].OfficePhoneSecondary.value + " ";
strText += document.forms[0].CellPhone.value + " ";
strText += document.forms[0].Pager.value + " ";
strText += document.forms[0].Fax.value + " ";
strText += document.forms[0].Notes.value + " ";
document.forms[0].SearchText.value=strText;
}
function SetSubmitHandler()
{
document.forms[0].onsubmit = runWhenSubmitted;
}
window.onload = SetSubmitHandler;
</script>
3. On a display view, use the search tag with the SearchText field. This field does not have to be included in the display board.
<search field="SearchText" exact="false"></search>
This worked really well for me, thanks for the tip. Is anyone familiar with a way to reset the search field? The only way I am able to reset it now is to clear it and then click search again.
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:DoNotOptimizeForBrowser /> </w:WordDocument> </xml><![endif]--> <!-- /* Font Definitions */ @font-face {font-family:"Arial Unicode MS"; panose-1:2 11 6 4 2 2 2 2 2 4; mso-font-charset:128; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1 -369098753 63 0 4129023 0;} @font-face {font-family:"\@Arial Unicode MS"; panose-1:2 11 6 4 2 2 2 2 2 4; mso-font-charset:128; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1 -369098753 63 0 4129023 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} p {margin-right:0in; mso-margin-top-alt:auto; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Arial Unicode MS";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} -->
Christopher,
The only simple way that comes to mind would be to add a 'clear' button after the search button. This would actually do what you described (clear the field and then search for it), but it would do it automatically. I'll see if I can throw the code together and put it up here in the next couple days... unless of course someone else already has it.
Everyone else,
A side question for me; does anybody know of a way to change the default text for the button from 'search' to something else like 'name'?
Also, I am failing miserably at applying this search function multiple times on one page. Every time I enter something into one field, it automatically applies the term to all fields after it as well. So if I search for 'Bob' in the name field, it also searches for Bob in the address, agency, phone number, and radio call-sign at the same time. Which is fine if your name is Bob, you live at Bob, and work for Bob, in the Bob position, but otherwise it isn't very practical. If anyone can give me some insight it would be appreciated, because although this somewhat amusing, it is also extremely annoying at the same time.
I too have had difficulty in applying the search field multiple times so I tweaked how the custom filter was being formed, so instead of using multiple “search” tags I used the Search tags filter and manually put in the rest with a Textbox and a Select tag. Using the Textbox to input what text I was looking for and using the select box to identify the field I was looking in.
Search Field:
<select name="field">
<option></option>
<option value="MesasgeId">County/Jurisdiction</option>
<option value="positionname">Position</option>
<option value="type">Type</option>
<option value="Message">Message</option>
</select>
That Contains
<input type="text" id="searchfield" name="searchfield" value="" />
<button onclick=" window.top.pageBoard.BoardMgr.ApplyCustomFilter('304',document.getElementById('field').options[document.getElementById('field').selectedIndex].value,document.getElementById('searchfield').value,'false');window.top.internalReloadIgnoreNextRefresh();">
Search
</button>
<button onclick=" window.top.pageBoard.BoardMgr.ApplyCustomFilter('304','MessageId','','false');window.top.internalReloadIgnoreNextRefresh();">
Clear
</button>