Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Aaron Lett 21 posts 72 karma points
    Jan 20, 2015 @ 00:32
    Aaron Lett
    0

    Search from Drop Down List, Publishing Keys

    So I already have a custom Data Type (Training Category) utilizing a drop-down list. Every training event has this data type set to a specific category.

    I also have the drop down list in the search set to pull the pre-values utilizing:

    XPathNodeIterator iterator = umbraco.library.GetPreValues(1420);
    iterator.MoveNext();
    XPathNodeIterator preValues = iterator.Current.SelectChildren("preValue", "");
    

    And render the values in the drop down as such:

    <select>
    <option>- Select -</option>
        @while (preValues.MoveNext())
        {
            string preValue = preValues.Current.Value;
            <option value="@preValue">@preValue</option>
        }
    </select>
    

    So, what I want to do is return the training events depending upon which category is selected.

    Sample UI can be seen at [http://updated.ramquest.com/services/training][1]

    I also include a "search by keyword" function, which searches a pre-defined list of values. The macro in it's entirety is as follows:

    @using System.Web;
    @using System.Xml.XPath
    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @{
    
        string searchKeywords = string.Empty;
        if (Request["keywords"] != null)
        {
            searchKeywords = Request["keywords"].ToLower();
        }
    
        Dictionary<string, object> values = new Dictionary<string, object>();
        values.Add("searchString", searchKeywords);
    
        var items = Model.Trainings.Where("trainingTags.ToLower().Contains(searchString)", values).OrderBy("startDate");
    
        XPathNodeIterator iterator = umbraco.library.GetPreValues(1420);
        iterator.MoveNext();
        XPathNodeIterator preValues = iterator.Current.SelectChildren("preValue", "");
    
    
        <form name="searchForm" method="post">
            <div class="keywordsSearchBox">
                <h4>Search Training</h4>
                <div class="searchSection">
                    <label>Search by Keyword: </label>
                    <input type="text" id="keywords" name="keywords" value="@searchKeywords" />
                    <p class="searchSeparator">-or-</p>
                        <label>Search by Product: </label>
                        <select>
                            <option>- Select -</option>
                            @while (preValues.MoveNext())
                            {
                                string preValue = preValues.Current.Value;
                                <option value="@preValue">@preValue</option>
                            }
                        </select>
                    <input type="submit" value="Search" />
                </div>
            </div>
        </form>
    
        <div class="searchResults">
        <p><strong>Below are the next scheduled RamQuest trainings. Search for specific topics or keywords, or search "all" to see a complete list of RamQuest's training topics and dates.</strong></p>
    
        @if (items.Count() > 0 && searchKeywords == "")
            {
                <ul class="searchResultList">
                    @foreach (var item in items.Take(3))
                    {
    
                        <li>
                            <h3 class="headline">
                                <a href="@item.Url">@item.Title</a>
                            </h3>
                            <span>
                                <b>When: </b> @umbraco.library.ShortDate(@item.startDate.ToString(), false, "")
                                <br />
                                <b>Time: </b>@item.time
                                <br />
                                <b>Cost: </b> @item.cost
                                <br />
                                <b>Location: </b> @item.trainingLocation
                            </span>
                        </li>
                    }
                </ul>
            }
        else if (items.Count() > 0 && searchKeywords != "")
            {
                <ul class="searchResultList">
                    @foreach (var item in items)
                    {
    
                        <li>
                            <h3 class="headline">
                                <a href="@item.Url">@item.Title</a>
                            </h3>
                            <span>
                                <b>When: </b> @umbraco.library.ShortDate(@item.startDate.ToString(), false, "")
                                <br />
                                <b>Time: </b> @item.time
                                <br />
                                <b>Cost: </b> @item.cost
                                <br />
                                <b>Location: </b> @item.location
                            </span>
                        </li>
                    }
                </ul>
            }
        else if (items.Count() == 0 && Request["keywords"] != null)
            {
                <span>There are no matching training events</span>
            }
        </div>
    
    }
    

    So any ideas on how to call the categories when the drop box is utilized?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies