On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Ok, here's another question. I have four containers, and I want the user to be able to select a container to act as the "parent" for the search. Can this be done?
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
    • Something like this : http://www.evo.wangba.fr/index.php?id=255

      or like this : http://www.evo.wangba.fr/index.php?id=256


      This two demos have been done by customizing ajaxSearch through the config file.
      • Yes, I have been looking at those examples. But there's no source for the config files used, just the snippet call and the chunk tpls. Likewise the "toolbox" snippets, no code? [ed. note: sottwell last edited this post 8 years, 2 months ago.]
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
        • But there's no source for the config files used, just the snippet call and the chunk tpls.
          This is right. The main reason is that each solution depends of the search form elements and require to be adapted to each specific needs.
          So I never explained how the config could be used and I provided these kind of developments, only, as a development services.
          • Ah, that explains several hours of frustration. I thought I was being particularly stupid by not understanding how those "examples" worked. I was just mistaken in the purpose of the examples, thinking they were to explain how to configure AjaxSearch.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
            • I got it!

              Create a form with the addition of a select drop-down whose values are the IDs of the parent resources:
              <form id="[+as.formId+]" action="[+as.formAction+]" method="post">
                  <fieldset>
                  <label>
                        <input id="[+as.inputId+]" type="text" name="search" value="[+as.inputValue+]">
                  </label>
                 <label>
                      <select name="parents" id="selectParents" size="1">
                        <option value="1">One</option>
                        <option value="2">Two</option>
                        <option value="3">Three</option>
                      </select>
                </label>
                  [+as.liveSearch:is=`0`:then=`
                      <label>
                          <input id="[+as.submitId+]" type="submit" name="sub" value="[+as.submitText+]" />
                      </label>
                  `+]
                  </fieldset>
              </form>


              Create a custom config file and put it in the ajaxSearch/configs folder:
              $dcfg['parents'] = $_POST['parents'];


              And call AjaxSearch:
              [!AjaxSearch? &config=`one` &ajaxSearch=`0` &advSearch=`exactphrase` &showInputForm=`1` &tplInput=`asAdvSearchInput`!]
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
              • Here's one way to have a select drop-down that will maintain the user's selection while showing search results on the same page.
                <select id="asParents" name="parents">
                        <option value="0" [+as.selected:is=`0`:or:is=``:then=`selected="selected"`+]>All</option>
                        <option value="1" [+as.selected:is=`1`:then=`selected="selected"`+]>One</option>
                        <option value="2" [+as.selected:is=`2`:then=`selected="selected"`+]>Two</option>
                        <option value="3" [+as.selected:is=`3`:then=`selected="selected"+]>Three</option>
                </select>


                And in the config file:
                $dcfg['parents'] = $_POST['parents'];
                $modx->setPlaceholder("as.selected", $_POST['parents']);
                


                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org