Kategorien
- 3D-Simulation (6)
- Allgemeines zu ilexius (22)
- Internet & Web-Technologie (41)
- IT-Service (9)
- Suchmaschinen (21)
- TYPO3 (7)
- Web Programming (1)
Letzte Kommentare
- dit not work for me
- 30.08.2010 23:13
- Saved my day
- 06.07.2010 10:43
Letzte Beiträge
- Keywords für neue Produkte
- 01.07.2010 11:04
- Studentische Aushilfe gesucht
- 23.06.2010 11:23
- RealURL + tt_news XXX was not a keyword for a postVarSet...
- 17.06.2010 12:54
- Interessante Artikel zum Thema SEO...
- 07.06.2010 14:54
Activating Autocompleter in script.aculo.us when entering a field (on Focus)
Autocompletion is a very useful AJAX feature: it allows the user to enter common values in fields very fast. By default, autocomplete activates after you type in the first letter. If you only have a few values in the autocomplete list, this is not very useful. Better would be to show the autocomplete list as soon as the user enters the field (the field is becomes focus).
For example we may have a field named color and would like to propose only a few values to the user. Because autocomplete starts after typing the first letter, the user will never see all suggestions we provide for the field. It would be more useful to provide a list of colors instantly when the user enters the field. By default this does not work with script.aculo.us. The script.aculo.us autocompleter offers the option minChars. But this parameter can not be set to 0, because 0 is evaluated as Boolean false and triggers the default value which is 1.
Example:
new Ajax.Autocompleter('DocumentJournalTitle', 'DocumentJournalTitle_autoComplete',
'/autoComplete/journal_title',
{minChars:0, frequency:0.1});
This does not work as expected: Autocomplete is still triggered after typing the first character.
I developed a short work around:
Set minChars to -1, this evaluates to true and is smaller or equal to 0:
<input name="journal_title" type="text" id="DocumentJournalTitle"
autocomplete="off" value="" />
<script type="text/javascript">
new Ajax.Autocompleter('DocumentJournalTitle', 'DocumentJournalTitle_autoComplete',
'/autoComplete/journal_title',
{minChars:-1, frequency:0.1});
</script>
This still does not work as expected. Why? The autocompleter only listens for keypress events. When the user enteres the field, the autocompleter is not activated. So we need to fire the event manually. This works this way:
<input name="journal_title" type="text"
onFocus="doFireEvent(this,'keydown');"
id="DocumentJournalTitle" autocomplete="off" value="" />
<script type="text/javascript">
function doFireEvent(elem,event){
// IE
if (document.createEventObject){
var e = document.createEventObject();
return elem.fireEvent('on'+event,e)
}
// firefox and others
else{
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true ); // event type,bubbling,cancelable
return !elem.dispatchEvent(e);
}
}
new Ajax.Autocompleter('DocumentJournalTitle', 'DocumentJournalTitle_autoComplete',
'/Entwicklung/StudyBase/documents/autoComplete/journal_title',
{minChars:-1, frequency:0.1});
</script>
And now the autocomplete box will show as soon as the field gets focused :-)
Weiterer Text
- 2 Kommentar(e)
Saved my day
Thanks, just had exactly this problem and solved it!
dit not work for me
this did not work for me. i found another solution for my case:
var AutoCss = new Ajax.Autocompleter('aj_salesstatus', 'salesstatus_ac', 'ajax_salesstatus.php', {minChars:-1, afterUpdateElement: setmodified});
$('aj_salesstatus').observe('focus', function() {
AutoCss.activate();
});
$('aj_salesstatus').observe('click', function() {
AutoCss.activate();
});
ajax_salesstatus.php:
available
not available
on hold
sold
resale
unknown
This shows all entries onclick and onfocus. also it overwrites the complete content of the text input (so no compatibility with tokens), because otherwise if the prior selection was longer than the current, it will not be completely overwritten. hope this helps somebody with this issue of ajax.autocompleter.
