2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-01-09 05:18:36 +01:00
|
|
|
/**
|
|
|
|
* Autocompleting text field, using script.aculo.us
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-formattedinput
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class AutocompleteTextField extends TextField {
|
|
|
|
|
|
|
|
protected $optionsURL;
|
|
|
|
|
|
|
|
function __construct($name, $title = null, $optionsURL, $value = "", $maxLength = null){
|
|
|
|
$this->optionsURL = $optionsURL;
|
|
|
|
|
|
|
|
parent::__construct($name, $title, $value, $maxLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
function extraClass() {
|
|
|
|
return parent::extraClass() . " autocomplete";
|
|
|
|
}
|
|
|
|
|
|
|
|
function Field() {
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63175 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-28 15:12:20 +02:00
|
|
|
// Requirements::javascript(SAPPHIRE_DIR . '/javascript/AutocompleteTextField.js');
|
2008-04-06 06:08:45 +02:00
|
|
|
$attributes = array(
|
2008-10-21 22:58:11 +02:00
|
|
|
'class' => "{$this->class} text" . ($this->extraClass() ? $this->extraClass() : ''),
|
2008-04-06 06:08:45 +02:00
|
|
|
'type' => 'text',
|
|
|
|
'id' => $this->id(),
|
|
|
|
'name' => $this->name,
|
2008-04-09 13:21:22 +02:00
|
|
|
'value' => $this->Value(),
|
2008-09-17 01:14:31 +02:00
|
|
|
'tabindex' => $this->getTabIndex(),
|
2008-04-06 06:08:45 +02:00
|
|
|
'size' => $this->maxLength ? min( $this->maxLength, 30 ) : 30
|
|
|
|
);
|
|
|
|
if($this->maxLength) $attributes['maxlength'] = $this->maxLength;
|
|
|
|
|
|
|
|
return $this->createTag('input', $attributes) . "<div id=\"" . $this->id() . "_Options\" class=\"autocompleteoptions\"></div>";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function FieldHolder() {
|
|
|
|
$holder = parent::FieldHolder();
|
|
|
|
|
|
|
|
$id = $this->id();
|
|
|
|
|
|
|
|
$holder .= <<<JS
|
|
|
|
<script type="text/javascript">
|
|
|
|
new Ajax.Autocompleter( '$id', '{$id}_Options', '{$this->optionsURL}', { afterUpdateElement : function(el) { if(el.onajaxupdate) { el.onajaxupdate(); } } } );
|
|
|
|
</script>
|
|
|
|
JS;
|
|
|
|
|
|
|
|
return $holder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|