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() {
|
|
|
|
// Requirements::javascript('sapphire/javascript/AutocompleteTextField.js');
|
2008-04-06 06:08:45 +02:00
|
|
|
$attributes = array(
|
2008-08-08 00:26:49 +02:00
|
|
|
'class' => "{$this->class} text " . $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-04-06 06:08:45 +02:00
|
|
|
'tabindex' => $this->getTabIndexHTML(),
|
|
|
|
'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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|