We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    So I'm trying to integrate the select2 type ahead search tool for bootstrap with modx & a custom extra, There are several problems I think I need to solve, but here is what I have so far:

    Here is the search box:
    <div class="form-group collapse in" id="payee_uid">
    	<label class="col-md-4 control-label" for="payee_uid">Payee</label>
    	<div class="col-md-4">
    		<input type="hidden" id="wayees" name="payee_uid" class="form-control input-md" />
    	</div>
    </div>


    The js that controls it:
    $('#wayees').select2({
        minimumInputLength: 2,
        ajax: {
          url: "/connectors/search-connector.php",
          dataType: 'json',
          data: function (term, page) {
            return {
              q: term
            };
          },
          results: function (data, page) {
            return { results: data };
          }
        }
      });


    the search connector page, using the freeze uri to get the url & content type correct
    [[!flowthroughSearch? &search_what=`getJsonPayees`]]


    the flowthroughsearch snippet
    <?php
    $output = '';
    
      $search_base = $modx->getOption('core_path').'components/modflowthrough/model/';
    
      $search = $modx->getService('modflowthroughsearch', 'modFlowThroughSearch', $search_base, $scriptProperties);
      
      if (!$search instanceof modflowthroughsearch){
    	
    	return 'modflowthroughsearch broken';exit();
    
      }
      
      $output = $search->$scriptProperties['search_what']();
    
    return $output;



    and the function it calls:
    public function getJsonPayees(){
    
    	$options = $this->modx->getCollectionGraph('Employer', '{}');
    	
    	$output = array();
    	
    	foreach($options as $option){
    	
    		$push = array(
    			'id' => $option->get('id'),
    			'text' => $option->get('company_name').' '.$option->get('cams'),
    		);
    		
    		array_push($output, $push);
    
    	}
    	
    	return $this->modx->toJSON($output);
    	
    }








    To start, it seems to be a long roundabout way to get at this thing, I would like to build a little 'connector' in my core/components directory that loads modx & my custom extra model as well. and go from there. so:

    - the js builds a request that looks like: http://nlc.nexus.local/connectors/search-connector.php?q=nor&_=1399394702387, this gives a 404 error [probably because of the FURLs] , http://nlc.nexus.local/connectors/search-connector.php comes up no problem. How to fix that?

    - I have several modals that call this search [to different tables] several times & could potentially request large data sets, up to 10 times. How can I be sure I am only instantiating my modx & extras object once for all the requests? [because the JS is making individual requests won't it get created up to ten times?]

    - my core/components is not web accessible, I'm guessing I'll have to create a [another!] snippet that builds a url to access that file?



    Thoughts?
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525