Example #1
0
 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;
 }
 protected function getTextAreaAttributes()
 {
     $textarea_attrs = parent::getTextAreaAttributes();
     // If 'no autocomplete' was specified, print a regular
     // textarea instead.
     if (!array_key_exists('no autocomplete', $this->mOtherArgs) || $this->mOtherArgs['no autocomplete'] == false) {
         list($autocompleteSettings, $remoteDataType, $delimiter) = SFTextWithAutocompleteInput::setAutocompleteValues($this->mOtherArgs);
         if (!is_null($remoteDataType)) {
             $textarea_attrs['autocompletedatatype'] = $remoteDataType;
         }
         $textarea_attrs['autocompletesettings'] = $autocompleteSettings;
         $textarea_attrs['class'] .= ' autocompleteInput';
     }
     return $textarea_attrs;
 }
Example #3
0
 public static function getHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args)
 {
     global $sfgTabIndex, $sfgFieldNum;
     // For backward compatibility with pre-SF-2.1 forms
     if (array_key_exists('autocomplete field type', $other_args) && !array_key_exists('no autocomplete', $other_args)) {
         return SFTextWithAutocompleteInput::getHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
     }
     $className = 'createboxInput';
     if ($is_mandatory) {
         $className .= ' mandatoryField';
     }
     if (array_key_exists('class', $other_args)) {
         $className .= ' ' . $other_args['class'];
     }
     $input_id = "input_{$sfgFieldNum}";
     // Set size based on pre-set size, or field type - if field
     // type is set, possibly add validation too.
     // (This special handling should only be done if the field
     // holds a single value, not a list of values.)
     $size = 35;
     $inputType = '';
     if (array_key_exists('field_type', $other_args) && (!array_key_exists('is_list', $other_args) || !$other_args['is_list'])) {
         if ($other_args['field_type'] == 'number') {
             $size = 10;
             $inputType = 'number';
         } elseif ($other_args['field_type'] == 'URL') {
             $size = 100;
             $inputType = 'URL';
         } elseif ($other_args['field_type'] == 'email') {
             $size = 45;
             $inputType = 'email';
         }
     }
     if (array_key_exists('size', $other_args)) {
         $size = $other_args['size'];
     }
     $inputAttrs = array('id' => $input_id, 'tabindex' => $sfgTabIndex, 'class' => $className, 'size' => $size);
     if ($is_disabled) {
         $inputAttrs['disabled'] = 'disabled';
     }
     if (array_key_exists('maxlength', $other_args)) {
         $inputAttrs['maxlength'] = $other_args['maxlength'];
     }
     if (array_key_exists('placeholder', $other_args)) {
         $inputAttrs['placeholder'] = $other_args['placeholder'];
     }
     $text = Html::input($input_name, $cur_value, 'text', $inputAttrs);
     if (array_key_exists('uploadable', $other_args) && $other_args['uploadable'] == true) {
         if (array_key_exists('is_list', $other_args) && $other_args['is_list'] == true) {
             if (array_key_exists('delimiter', $other_args)) {
                 $delimiter = $other_args['delimiter'];
             } else {
                 $delimiter = ',';
             }
         } else {
             $delimiter = null;
         }
         if (array_key_exists('default filename', $other_args)) {
             $default_filename = $other_args['default filename'];
         } else {
             $default_filename = '';
         }
         $text .= self::uploadableHTML($input_id, $delimiter, $default_filename, $cur_value, $other_args);
     }
     $spanClass = 'inputSpan';
     if ($inputType !== '') {
         $spanClass .= " {$inputType}Input";
     }
     if ($is_mandatory) {
         $spanClass .= ' mandatoryFieldSpan';
     }
     $text = Html::rawElement('span', array('class' => $spanClass), $text);
     return $text;
 }
	public static function getParameters() {
		$params = parent::getParameters();
		$params = array_merge( $params, SFTextWithAutocompleteInput::getAutocompletionParameters() );
		return $params;
	}
 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);
 }
 public static function getParameters()
 {
     $params = parent::getParameters();
     $params[] = array('name' => 'size', 'type' => 'int', 'description' => wfMessage('sf_forminputs_size')->text());
     $params[] = array('name' => 'placeholder', 'type' => 'string', 'description' => wfMessage('sf_forminputs_placeholder')->text());
     $params[] = array('name' => 'existing values only', 'type' => 'boolean', 'description' => wfMessage('sf_forminputs_existingvaluesonly')->text());
     $params[] = array('name' => 'max values', 'type' => 'int', 'description' => wfMessage('sf_forminputs_maxvalues')->text());
     $params = array_merge($params, SFTextWithAutocompleteInput::getAutocompletionParameters());
     return $params;
 }