/**
  * This test was created to test the change to preg_split() in setValues() due
  * to the PHP 5.3 deprecation of the split() function.
  * http://bugs.weblite.ca/view.php?id=809
  */
 function testPregSplit()
 {
     $select = new HTML_QuickForm_select('test', 'Test', array('a1' => 'Tom', 'b2' => 'Dick', 'c3' => 'Harry'));
     $select->setMultiple(true);
     $select->setSelected('a1');
     $this->assertEquals(array(0 => 'a1'), $select->getSelected(), 'setSelected failed to select value.');
     $select->setSelected('a1, c3');
     $this->assertEquals(array(0 => 'a1', 1 => 'c3'), $select->getSelected(), 'setSelectedFailed to select double value.');
 }
예제 #2
0
 function toHtml()
 {
     if ($this->_flagFrozen) {
         return $this->getFrozenHtml();
     }
     //		$commUtil = new Common_Util();
     $lastPicker = $_REQUEST[$this->_multiname . "PICKER"];
     //$commUtil->request($this->_multiname."PICKER");
     //		$out .= "<script src='/Html/JS/multichooser.js' language='Javascript' type='text/Javascript'></script>\n";
     $out .= "<table>";
     if ($this->_usePicker) {
         //$pickerVals = array("0"=>"Please Select...");
         $pickerVals = array();
         $optionArray = array();
         foreach ($this->_pickerOptions as $label => $options) {
             $pickerVals[] = $label;
             $optionArray[] = $options;
         }
         $elementName = $this->_multiname;
         $out .= "<tr><td colspan='4'><Br><Br>\n";
         $out .= "<script type='text/javascript'>";
         $out .= "var PickerData{$elementName} = [[]";
         foreach ($this->_pickerOptions as $labelSet => $optionSet) {
             $lableArr = explode(',', $labelSet);
             $lableKey = $lableArr[1];
             $out .= ",";
             //'".$lableKey."'
             $first = 1;
             if (sizeof($optionSet)) {
                 foreach ($optionSet as $value => $label) {
                     if ($first == 1) {
                         $first = 0;
                     } else {
                         $out .= ",";
                     }
                     $label = preg_replace("/\\'/", "\\'", $label);
                     $out .= "['{$lableKey}', '{$value}','{$label}']";
                 }
             } else {
                 $out .= "[]";
             }
             $out .= "\n";
         }
         $out .= "];\n";
         $out .= "</script>";
         $out .= "<b>" . $this->_pickerLabel . "</b>&nbsp;";
         $pickerValsArr = array();
         for ($index = 0; $index < sizeof($pickerVals); $index++) {
             $array_element = explode(',', $pickerVals[$index]);
             $key = $array_element[1];
             $value = $array_element[0];
             $pickerValsArr[$key] = $value;
         }
         $picker = new HTML_QuickForm_select($elementName . "PICKER", "", $pickerValsArr, $attributes . " id='{$elementName}PICKER' onchange=\"multichooserPick('{$elementName}')\"");
         $picker->setSize(1);
         $picker->setSelected($lastPicker);
         $out .= $picker->toHtml();
         $out .= "</td></tr>\n";
     }
     $out .= "<tr><td>";
     if ($this->_autoComplete) {
         $out .= $this->txt->toHtml() . "<br>";
     }
     $out .= "<b>" . $this->_fromLabel . "</b><br>";
     $out .= $this->_fromBox->toHtml();
     $out .= "</td><td>";
     $out .= $this->_addButton->toHtml();
     $out .= "<br>";
     $out .= $this->_remButton->toHtml();
     $out .= "</td><td>";
     $out .= "<b>" . $this->_toLabel . "</b><br>";
     $out .= $this->_inBox->toHtml();
     $out .= "</td></tr></table>\n";
     $out .= $this->_hidden->toHtml();
     $out .= "<script type='text/javascript'>document.getElementById('" . $this->_multiname . "').value = '" . $this->_hidden->getValue() . "';</script>";
     return $out;
 }
예제 #3
0
파일: altselect.php 프로젝트: fferriere/web
 /**
  * Set the selected options.  If a non-listed option is specified, it
  * will go into the other text field.  Note at this point, the other and
  * multiple attributes may not have been set.
  *
  * @param   mixed  $values array or comma delimited string of selected values
  * @access  public
  * @return  void
  */
 function setSelected($values)
 {
     parent::setSelected($values);
     //
     // we need to do some extra work here in case the other
     // option will be/has been set...
     //
     $other_values = array();
     foreach ($this->_values as $value) {
         // if we are in singular mode and the other button is selected from
         // the submit values then we'll need to record the real other value
         // in _otherValue
         if ($value == '_qf_other') {
             $myName = $this->getName();
             $this->_otherValue = @$_REQUEST[$myName . '_qf_other'];
             // we only need to grasp the first other value, because we
             // are in singular mode, so we'll return...
             return;
         } else {
             $found = false;
             foreach ($this->_options as $option) {
                 if ((string) $value == (string) $option['attr']['value']) {
                     $found = true;
                 }
             }
             if (!$found) {
                 $this->_values[] = '_qf_other';
                 $other_values[] = $value;
             }
         }
     }
     if (!empty($other_values)) {
         $this->_otherValue = implode(',', $other_values);
     }
 }