"Filter your search" function under Tags

edited February 2016 in Modules
Hi

The "Filter your search" function under my "many to many" tags doesn't work, is I miss something?

I've added the following in my model to active the "many to many"
public $has_many = array('programmes' => array(FUEL_FOLDER => 'programmes_model'));

Thanks a lot.

Azid

Comments

  • edited 3:46PM
    Here is some more information on customizing how the search filters for your model:
    http://docs.getfuelcms.com/modules/simple#filtering
  • edited 3:46PM
    I've studied the docs and try but not success, can anyone give me a hits please?

    The "Filter your search" under $has_many programme tags still doesn't work.

    Here is my models original code:
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once(FUEL_PATH.'models/base_module_model.php'); class Papers_model extends Base_module_model { public $filters = array('year', 'ep_subject.code', 'ep_subject.title'); public $required = array('year', 'sem_id', 'subject_id', 'pdf_file'); public $foreign_keys = array( 'sem_id' => 'semesters_model', 'subject_id' => 'subjects_model', 'college_id' => 'colleges_model' ); public $has_many = array('programmes' => array(FUEL_FOLDER => 'programmes_model')); function __construct() { parent::__construct('ep_paper'); // table name } function list_items($limit = NULL, $offset = NULL, $col = 'ep_paper.year', $order = 'desc', $just_count = FALSE) { $this->db->join('ep_sem', 'ep_sem.id = ep_paper.sem_id', 'left'); $this->db->join('ep_subject', 'ep_subject.id = ep_paper.subject_id', 'left'); $this->db->join('ep_college', 'ep_college.id = ep_paper.college_id', 'left'); $this->db->select('ep_paper.id, ep_paper.year, ep_sem.semester, ep_subject.code AS Subject_Code, ep_subject.title AS Subject_Name, ep_college.college, ep_paper.pdf_file AS PDF_File, ep_paper.date_added, ep_paper.published', FALSE); $data = parent::list_items($limit, $offset, $col, $order, $just_count); return $data; } function form_fields($values = array(), $related = array()) { $fields = parent::form_fields($values, $related); // ******************* ADD CUSTOM FORM STUFF HERE ******************* $fields['pdf_file'] = array('name' => 'PDF_File'); return $fields; } } class paper_model extends Base_module_record { // put your record model code here }
  • edited 3:46PM
    Filtering on the has_many relationships is a little tricky. It requires joining and filtering on the fuel_relationships table. I would recommend doing the following 3 things:
    1. Add the following to your fuel/application/config/MY_fuel_modules.php under your configuration for the 'programmes' module. This will provide a larger space for filtering. This step isn't necessary and instead of "collapse" you can use "popover" which will place an arrow in the Search field that can be used to expose additional filters. Without specifying it, it will appear right next to the search box.
    $config['modules']['programmes'] = array( // ... other configuration 'advanced_search' => 'collapse', );

    2. Create a "filters" method on your Papers_model. This same effect can be done using the "filters" parameter on the module's configuration (fuel/application/config/MY_fuel_modules.php), but this is a little easier most of the time:
    function filters($values = array()) { $fields['tags']['first_option'] = lang('label_select_one'); $fields['tags']['type'] = 'select2'; $fields['tags']['multiple'] = TRUE; $fields['tags']['module'] = NULL; // other fields you want to use as filters return $fields; }

    3. In your Papers_model::list_items method, you'll need to setup special code to do the joining to the fuel_relationships table and adding the where_in clause. Note that you must unset the filter afterwards so it doesn't try and get processed later down in the method:
    function list_items($limit = NULL, $offset = NULL, $col = 'last_updated', $order = 'desc', $just_count = FALSE) { if (!empty($this->filters['programmes'])) { $this->db->where_in('fuel_relationships.foreign_key', $this->filters['programmes']); $this->db->join('fuel_relationships', 'fuel_relationships.candidate_key = proofer_projects.id', 'LEFT'); $this->db->group_by('fuel_relationships.candidate_key'); unset($this->filters['programmes']); } // ... the reset of your list_items code here }
  • edited 3:46PM
    Hi Admin,

    I tried your suggestion but doesn't success and I think I make you confused my question by my poor english.

    I've captured my page FYI, the high-lighted area is the $has_many filter and I hope it can be filter the programme code.

    https://www.dropbox.com/s/ct5gif2x3m5iblp/ScreenHunter_364 Feb. 12 21.54.jpg?dl=0

    Many thanks.
  • edited February 2016
    Sorry, I misunderstood your message completely. When you say it doesn't work, did you type 3 or more characters? And are you seeing any javascript errors in your console?
  • edited 3:46PM
    Yes, I'd type number or characters. Attached a capture FYI
    https://www.dropbox.com/s/xy6gj3t6yt7184l/ScreenHunter_365 Feb. 13 21.55.jpg?dl=0
  • edited 3:46PM
    Thanks for the screenshot. If you don't mind, can you do the following:
    1. Open up the fuel/modules/fuel/assets/js/jquery/plugins/jquery.supercomboselect.js
    2. Change line 230 wrapping text with String like so:
    var index = String(text).toLowerCase().indexOf(val);
    3. Browse to fuel/build (must be logged in). This will recompile the javascript and CSS files
    4. Go back to page with problem and refresh and test if that javascript error still appears.
  • edited 3:46PM
    I've pushed a fix to the develop and 1.4_dev branch that should take care of that issue:
    https://github.com/daylightstudio/FUEL-CMS/commit/3e5481716bd45f9ea81f6ea2f5859bb47d5f243d
  • edited February 2016
    Hi Admin,

    Yeah...it fixed. I replaced fuel.min and jquery.supercomboselect.js by using 1.4_dev version, then replace the line 231 in jquery.supercomboselect.js with:

    var index = String(text).toLowerCase().indexOf(val);

    It works now~~~thanks admin!!!
Sign In or Register to comment.