[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/form/ -> searchableselector.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * searchable select type element
  19   *
  20   * Contains HTML class for a searchable select type element
  21   *
  22   * @package   core_form
  23   * @copyright 2009 Jerome Mouneyrac <[email protected]>
  24   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  require_once ('select.php');
  28  
  29  /**
  30   * searchable select type element
  31   *
  32   * Display a select input with a search textfield input on the top
  33   * The search textfield is created by the javascript file searchselector.js
  34   * (so when javascript is not activated into the browser, the search field is not displayed)
  35   * If ever the select can be reset/unselect/blank/nooption, you will have to add an option "noselected"
  36   * and manage this special case when you get/set the form data (i.e. $mform->get_data()/$this->set_data($yourobject)).
  37   *
  38   * @package   core_form
  39   * @category  form
  40   * @copyright 2009 Jerome Mouneyrac
  41   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42   */
  43  class MoodleQuickForm_searchableselector extends MoodleQuickForm_select{
  44      /**
  45       * Constructor
  46       *
  47       * @param string $elementName Select name attribute
  48       * @param mixed $elementLabel Label(s) for the select
  49       * @param array $options additional options.
  50       * @param mixed $attributes Either a typical HTML attribute string or an associative array
  51       */
  52      function MoodleQuickForm_searchableselector($elementName=null, $elementLabel=null, $options=null, $attributes=null) {
  53          //set size default to 12
  54          if (empty($attributes) || empty($attributes['size'])) {
  55              $attributes['size'] = 12;
  56          }
  57          parent::MoodleQuickForm_select($elementName, $elementLabel, $options, $attributes);
  58      }
  59  
  60      /**
  61       * Returns the select element in HTML
  62       *
  63       * @return string
  64       */
  65      function toHtml(){
  66          global $OUTPUT;
  67          if ($this->_hiddenLabel || $this->_flagFrozen) {
  68              return parent::toHtml();
  69          } else {
  70              // Javascript for the search/selection fields
  71              global $PAGE;
  72              $PAGE->requires->js('/lib/form/searchableselector.js');
  73              $PAGE->requires->js_function_call('selector.filter_init', array(get_string('search'),$this->getAttribute('id')));
  74  
  75              $strHtml = '';
  76              $strHtml .= parent::toHtml(); //the select input
  77              return $strHtml;
  78          }
  79      }
  80  
  81  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1