r82812 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82811‎ | r82812 | r82813 >
Date:20:10, 25 February 2011
Author:yaron
Status:deferred
Tags:
Comment:
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) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.php
@@ -524,6 +524,7 @@
525525 }
526526
527527 static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 528+ // For backward compatibility with pre-SF-2.1 forms
528529 if ( array_key_exists( 'no autocomplete', $other_args ) &&
529530 $other_args['no autocomplete'] == true ) {
530531 unset( $other_args['autocompletion source'] );
@@ -565,24 +566,37 @@
566567 $values = SFUtils::getAutocompleteValues($autocompletion_source, $autocomplete_field_type );
567568 $autocompletion_source = str_replace( "'", "\'", $autocompletion_source );
568569
569 - $divClass = "ui-widget";
570 - if ($is_mandatory) { $divClass .= " mandatory"; }
571 - $text =<<<END
572 -<div class="$divClass">
573 - <select id="input_$sfgFieldNum" name="$input_name" class="$className" tabindex="$sfgTabIndex" autocompletesettings="$autocompletion_source" comboboxwidth="$pixel_width">
574 - <option value="$cur_value"></option>
 570+ $optionsText = Xml::element( 'option', array( 'value' => $cur_value ), null, false ) . "\n";
 571+ foreach ( $values as $value ) {
 572+ $optionsText .= Xml::element( 'option', array( 'value' => $value ), $value ) . "\n";
 573+ }
575574
576 -END;
577 - foreach ($values as $value) {
578 - $text .= " <option value=\"$value\">$value</option>\n";
 575+ $selectAttrs = array(
 576+ 'id' => "input_$sfgFieldNum",
 577+ 'name' => $input_name,
 578+ 'class' => $className,
 579+ 'tabindex' => $sfgTabIndex,
 580+ 'autocompletesettings' => $autocompletion_source,
 581+ 'comboboxwidth' => $pixel_width,
 582+ );
 583+ if ( array_key_exists( 'existing values only', $other_args ) ) {
 584+ $selectAttrs['existingvaluesonly'] = 'true';
579585 }
580 - $text .= <<<END
581 - </select>
582 -</div>
583 -END;
 586+ $selectText = Xml::tags( 'select', $selectAttrs, $optionsText );
584587
 588+ $divClass = "ui-widget";
 589+ if ($is_mandatory) { $divClass .= " mandatory"; }
 590+ $text = Xml::tags( 'div', array( 'class' => $divClass ), $selectText );
585591 return $text;
586592 }
 593+
 594+ public static function getParameters() {
 595+ $params = parent::getParameters();
 596+ $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_size' ) );
 597+ $params = array_merge( $params, SFEnumInput::getValuesParameters() );
 598+ $params[] = array( 'name' => 'existing values only', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_existingvaluesonly' ) );
 599+ return $params;
 600+ }
587601 }
588602
589603 class SFTextWithAutocompleteInput extends SFTextInput {