http://www.mediawiki.org/wiki/Special:Code/MediaWiki/82812

Revision: 82812
Author:   yaron
Date:     2011-02-25 20:10:15 +0000 (Fri, 25 Feb 2011)
Log Message:
-----------
Added handling for 'existing values only' parameter for SFComboBoxInput; also 
replaced some of the hardcoded HTML with calls to the Xml class

Modified Paths:
--------------
    trunk/extensions/SemanticForms/includes/SF_FormInputs.php

Modified: trunk/extensions/SemanticForms/includes/SF_FormInputs.php
===================================================================
--- trunk/extensions/SemanticForms/includes/SF_FormInputs.php   2011-02-25 
20:01:07 UTC (rev 82811)
+++ trunk/extensions/SemanticForms/includes/SF_FormInputs.php   2011-02-25 
20:10:15 UTC (rev 82812)
@@ -524,6 +524,7 @@
        }
 
        static function getHTML( $cur_value, $input_name, $is_mandatory, 
$is_disabled, $other_args ) {
+               // For backward compatibility with pre-SF-2.1 forms
                if ( array_key_exists( 'no autocomplete', $other_args ) &&
                                $other_args['no autocomplete'] == true ) {
                        unset( $other_args['autocompletion source'] );
@@ -565,24 +566,37 @@
                $values = 
SFUtils::getAutocompleteValues($autocompletion_source, $autocomplete_field_type 
);
                $autocompletion_source = str_replace( "'", "\'", 
$autocompletion_source );
 
-               $divClass = "ui-widget";
-               if ($is_mandatory) { $divClass .= " mandatory"; }
-               $text =<<<END
-<div class="$divClass">
-       <select id="input_$sfgFieldNum" name="$input_name" class="$className" 
tabindex="$sfgTabIndex" autocompletesettings="$autocompletion_source" 
comboboxwidth="$pixel_width">
-               <option value="$cur_value"></option>
+               $optionsText = Xml::element( 'option', array( 'value' => 
$cur_value ), null, false ) . "\n";
+               foreach ( $values as $value ) {
+                       $optionsText .= Xml::element( 'option', array( 'value' 
=> $value ), $value ) . "\n";
+               }
 
-END;
-               foreach ($values as $value) {
-                       $text .= "              <option 
value=\"$value\">$value</option>\n";
+               $selectAttrs = array(
+                       'id' => "input_$sfgFieldNum",
+                       'name' => $input_name,
+                       'class' => $className,
+                       'tabindex' => $sfgTabIndex,
+                       'autocompletesettings' => $autocompletion_source,
+                       'comboboxwidth' => $pixel_width,
+               );
+               if ( array_key_exists( 'existing values only', $other_args ) ) {
+                       $selectAttrs['existingvaluesonly'] = 'true';
                }
-               $text .= <<<END
-       </select>
-</div>
-END;
+               $selectText = Xml::tags( 'select', $selectAttrs, $optionsText );
 
+               $divClass = "ui-widget";
+               if ($is_mandatory) { $divClass .= " mandatory"; }
+               $text = Xml::tags( 'div', array( 'class' => $divClass ), 
$selectText );
                return $text;
        }
+
+       public static function getParameters() {
+               $params = parent::getParameters();
+               $params[] = array( 'name' => 'size', 'type' => 'int', 
'description' => wfMsg( 'sf_forminputs_size' ) );
+               $params = array_merge( $params, 
SFEnumInput::getValuesParameters() );
+               $params[] = array( 'name' => 'existing values only', 'type' => 
'boolean', 'description' => wfMsg( 'sf_forminputs_existingvaluesonly' ) );
+               return $params;
+       }
 }
 
 class SFTextWithAutocompleteInput extends SFTextInput {


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to