public 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']); return SFTextInput::getHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args); } global $sfgTabIndex, $sfgFieldNum; $className = 'sfComboBox'; if ($is_mandatory) { $className .= ' mandatoryField'; } if (array_key_exists('class', $other_args)) { $className .= ' ' . $other_args['class']; } if (array_key_exists('size', $other_args)) { $size = $other_args['size']; } else { $size = '35'; } // There's no direct correspondence between the 'size=' // attribute for text inputs and the number of pixels, but // multiplying by 6 seems to be about right for the major // browsers. $pixel_width = $size * 6 . 'px'; list($autocompleteFieldType, $autocompletionSource) = SFTextWithAutocompleteInput::getAutocompletionTypeAndSource($other_args); // @TODO - that count() check shouldn't be necessary if (array_key_exists('possible_values', $other_args) && count($other_args['possible_values']) > 0) { $values = $other_args['possible_values']; } elseif ($autocompleteFieldType == 'values') { $values = explode(',', $other_args['values']); } else { $values = SFUtils::getAutocompleteValues($autocompletionSource, $autocompleteFieldType); } $autocompletionSource = str_replace("'", "\\'", $autocompletionSource); $optionsText = Html::element('option', array('value' => $cur_value), null, false) . "\n"; foreach ($values as $value) { $optionsText .= Html::element('option', array('value' => $value), $value) . "\n"; } $selectAttrs = array('id' => "input_{$sfgFieldNum}", 'name' => $input_name, 'class' => $className, 'tabindex' => $sfgTabIndex, 'autocompletesettings' => $autocompletionSource, 'comboboxwidth' => $pixel_width); if (array_key_exists('origName', $other_args)) { $selectAttrs['origname'] = $other_args['origName']; } if (array_key_exists('existing values only', $other_args)) { $selectAttrs['existingvaluesonly'] = 'true'; } $selectText = Html::rawElement('select', $selectAttrs, $optionsText); $divClass = 'ui-widget'; if ($is_mandatory) { $divClass .= ' mandatory'; } $text = Html::rawElement('div', array('class' => $divClass), $selectText); return $text; }
public static function setAutocompleteValues($field_args) { global $sfgAutocompleteValues, $sfgMaxLocalAutocompleteValues; list($autocompleteFieldType, $autocompletionSource) = SFTextWithAutocompleteInput::getAutocompletionTypeAndSource($field_args); $remoteDataType = null; if (array_key_exists('remote autocompletion', $field_args) && $field_args['remote autocompletion'] == true) { $remoteDataType = $autocompleteFieldType; } elseif ($autocompletionSource !== '') { // @TODO - that count() check shouldn't be necessary if (array_key_exists('possible_values', $field_args) && count($field_args['possible_values']) > 0) { $autocompleteValues = $field_args['possible_values']; } elseif ($autocompleteFieldType == 'values') { $autocompleteValues = explode(',', $field_args['values']); } else { $autocompleteValues = SFUtils::getAutocompleteValues($autocompletionSource, $autocompleteFieldType); } if (count($autocompleteValues) > $sfgMaxLocalAutocompleteValues && $autocompleteFieldType != 'values' && !array_key_exists('values dependent on', $field_args) && !array_key_exists('mapping template', $field_args)) { $remoteDataType = $autocompleteFieldType; } $sfgAutocompleteValues[$autocompletionSource] = $autocompleteValues; } $autocompletionSource = str_replace("'", "\\'", $autocompletionSource); return array($autocompletionSource, $remoteDataType); }