|
To help you Dmitriy, an autosuggest field doesn't work with the way you are trying to initialize the field. I worked to find a way to do just what you are after and would like to help. It is a different way to look at it. The problem with the new field is that for the autosuggest script to work it needs to be initialized. Another part of the problem is that the onfocus event is used and captured within the script so, my solution is as follows:
Add a new function to the page or a different script attached to the page:
var autoc;
function create_auto(id, data){
autoc = new autosuggest(id, data);
}
and then within the input field tag you need to create the autosuggest add:
onfocus="create_auto(this.id, array)"
this way the field gets initialized when it recieves focus and bypasses the onfocus used in the script
I hope this helps
|
|
|
|
|
The link downloads a version from 2007. May I get the latest code please?
|
|
|
|
|
Oh! There seems to be some mistake at Codeproject's side. I've written to them.
For now - you can write me at dmitrykhudorozhkov@yahoo.com, I'll send you the latest version.
Regards,
Dmitriy.
Listen up! "Teamwork" means staying out of my way! (Seifer, Final Fantasy 8).
|
|
|
|
|
Hi Dmitry
You have done some excellent work here.
I'm having a small issue with having more than one on a page though.
I'm using a client side array and set up the autosuggest to use_scroll = true.
The issue i have is that although the first auto suggest works perfectly, the subsequent ones do not allow for the scroll bar to be moved using the mouse. Using up and down keys is fine and using the mousewheel is also fine.
Clicking on the autosuggest scroll just makes the list dissappear.
This seems to be an issue in IE6/7/8 and Chrome. These are ones i've tested on.
I have tested on FF3 and it seems to work ok.
Any ideas?
Dan
|
|
|
|
|
Hi Dan,
does the sample in the article's archive work ok for you? It uses the exact same configuration that you've described.
Also, are there any errors shown in IE?
Regards,
Dmitriy.
Listen up! "Teamwork" means staying out of my way! (Seifer, Final Fantasy 8).
|
|
|
|
|
Hi
Thanks for the quick reply.
Actually i found that it does work in all the browsers, but i did some testing on the sample in the archive and this issue occurs when the text boxes are rendered off screen, ie, when you have to scroll down the page to reach the text boxes.
The page i'm having the issue with is as described. If i move the text boxes up so they appear nearer the top of the page, then it works fine.
Although that is not the solution i'm looking for, since i want it displayed lower down the page.
thanks
Dan
modified on Monday, August 24, 2009 4:06 AM
|
|
|
|
|
Hi Dmitriy
I found what the issue is.
Its due to the use of a doctype, XHTML in my case. The reference to the document.body.scrollTop becomes incorrect, so i used a piece of code from here...
http://www.javascriptkit.com/javatutors/static2.shtml[^]
A worthwhile addition i think.
Keep up the good work.
Dan
|
|
|
|
|
FINALLY, you detected the problem that I had. I am also using xhtml and can't change to html.
When using xhtml the mouse doesn't work properly in IE.
Thanks and I'll be looking forward the xhtml-compatible version of the script
Best Regards
|
|
|
|
|
Hi,
I have generated a simple php file that generates the following xml file:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<listdata>Canada|USA|United Kingdom</listdata>
The php file is as follows:
<?php
$host = "xxxx";
$database = "xxxx";
$user = "xxxx";
$password = "xxxx";
mysql_connect($host,$user,$password);
mysql_select_db($database);
$sql = "SELECT name FROM Creditor WHERE fk_client_id = 1";
$rs = mysql_query($sql);
header('Content-Type: application/xml;');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n";
?>
<listdata>
Canada|USA|United Kingdom
</listdata>
The autosuggest is invoked as follows:
<label class="block"><span>Crediteur</span><input type="text" name="inputcrediteur" id="inputcrediteur" size="35"/></label>
<script>
var obj = new autosuggest("inputcrediteur", "", "/retrieve_creddeb.php?");
</script>
When I run the page and start typing in the input box, it shows an error on line 1259 saying that this.keywords.0 is null or not an object. Firebug shows that the this.keywords variables are 'undefined'.
I am quite new to all this, so I am assuming I am overlooking something extremely trivial. I would very much appreciate anyone's help in this.
By the way, the autosuggest functionality does work when I use it based on arrays.
Thanks in advance,
Ronald.
|
|
|
|
|
Good evening,
this is a very strange bug - right now I'm trying to debug the issue.
As a quick solution, I can recommend you to set the full_refresh variable to true - this will allow the code to skip the problematic line.
Best regards,
Dmitriy.
Listen up! "Teamwork" means staying out of my way! (Seifer, Final Fantasy 8).
|
|
|
|
|
Found.
There is a bug in the code. The block:
if(comma != -1)
{
var ci = ca.split(that.item_delimiter);
that.keywords[i] = that.keywords_init[i] = ci[0];
that.values[i] = that.values_init[i] = ci[1];
}
else
{
that.values[i] = that.values_init[i] = "";
}
should be:
if(comma != -1)
{
var ci = ca.split(that.item_delimiter);
that.keywords[i] = that.keywords_init[i] = ci[0];
that.values[i] = that.values_init[i] = ci[1];
}
else
{
that.keywords[i] = that.keywords_init[i] = ca;
that.values[i] = that.values_init[i] = "";
}
Sorry for this.
Listen up! "Teamwork" means staying out of my way! (Seifer, Final Fantasy 8).
|
|
|
|
|
Works! Many thanks indeed for your extremely quick reply!
Best regards,
Ronald.
|
|
|
|
|
Hi Dmitry !
Glad to see that you continue to support your "child", and it justly became very popular.
Nevertheless two notes.
One - minor bug: the name of the variable use_IFrame is used with different case, so it always works as false.
Second - suggestion. May be it has sense to add to the autosuggest object one more property - id. Say, this.id=this.field_id + '_actd' . It may be useful when you have several autosuggest objects and want to use the single OnSelect function.
Regards,
Gennady
My English is permanently under construction. Be patient !!
|
|
|
|
|
Forgot one more suggestion, that as far as I remember, I've already suggested in the past.
So the thead may be called "Three things"
I'm speaking about styling. It would be much more convenient,
if the suggestions style will be in the external css.
And leave the default style inline.
Regards,
Gennady
My English is permanently under construction. Be patient !!
|
|
|
|
|
Good evening,
On your notes:
1. Thank you for pointing on the use_IFrame - will fix it in next release (next week).
2. You can use a single OnSelect now too - just define it as a separate named function:
function onSelect(control, index)
{
...
}
and use it wil any number of autosuggest objects:
new autosuggest("field1", custom_array_2, null, onSelect);
new autosuggest("field2", custom_array_2, null, onSelect);
...
If you still need to access the autosuggest object, you can do it through the input field it is bound to:
document.getElementById("field1").autosuggest
3. CSS for styles is high on my work list - will be done for the next release.
Best regards,
Dmitriy.
Listen up! "Teamwork" means staying out of my way! (Seifer, Final Fantasy 8).
|
|
|
|
|
Hi Dmitry!
Think, I didn't explain clear enough my question concerning control ID. It is needed not to get access to the control, but in the first place - to recognize control. For instance:
function ItemSelected(index, control) {
switch (control.id)
{
case 'BRANCH_CODE_ACTB':
CleanDependentDDL('ROVA_CODE_ACTB');
<......>
return;
break;
case 'ROVA_CODE_ACTB':
CleanDependentDDL('AREA_CODE_ACTB');
<......>
return;
break;
}
}
I know that I can use control.field_id property, but to consistency and readability of the program it would be better not to use "indirection".
Regards,
Gennady
My English is permanently under construction. Be patient !!
|
|
|
|
|
Hi Dmitry,
Testing the "restrict list" feature I noticed that if I typed certain characters (2nd Letter) that were not part of the word in the list, then the list disappeared. For instance if my list contained "apple", and I type "a", "apple" would appear. If I then type "s" then the restrict is somehow bypassed and "apple" disappears. It only does it with some letters - and changes depending on what word is in the list. It also does it whether the 2nd letter type is not in the entire word or another word in the list. Strange? IE and chrome.
Regards
Collin
Ok did some more checking if the JS script is set to "autocomplete to beginning of word", the restrict script does not take this into account. It will only restrict typing based on what is in the entire array. That is why you can type a second letter even if does not appear in the list because that letter combination might appear elsewhere in the array.
modified on Saturday, August 15, 2009 7:45 PM
|
|
|
|
|
Hi,
seems like a bug; I'll try to take care of it till the next release (early next week, I hope).
Regards,
Dmitriy.
Listen up! "Teamwork" means staying out of my way! (Seifer, Final Fantasy 8).
|
|
|
|
|
Hi Dmitry,
Thanks for all your hard work on improving the code.
Just a question for some thought.
I have an array which is produced from a DB. I have managed to incorporate this autosuggest quite well and was wondering if there are any limitations in the code for the length or size of the array.
For instance when I create an array from my DB recordset the autosuggest seems to stop working after 117 comma separated array. I can echo the entire array onto the page so its not a server side issue. It (autosuggest)just seems to stop after a certain length.
Regards
Collin
|
|
|
|
|
Good morning,
there is no limitation on the length of the client-side array; I have successfully tested the script with arrays with 6000 (six thousand) records and it worked ok.
Problems usually arise because of incorrect escaping (any quotes in the records?). If something stops working - are there any errors shown in Firefox's error console?
Best regards,
Dmitriy.
Listen up! "Teamwork" means staying out of my way! (Seifer, Final Fantasy 8).
|
|
|
|
|
Dmitry,
Thanks for the reply,
After investigating the record data in the array I did find traces of characters that corrupt the string. The only ones that corrupt the array were (single quotation) ' and \ (back slash). Surprisingly a comma , or double quotation " had no effect.
This would probably mean I need to cleanse my data on data entry.?
Regards
Collin
|
|
|
|
|
kernel1969 wrote: This would probably mean I need to cleanse my data on data entry.?
Maybe (or maybe not). All this means that in the end (when you output the array to the page) you must output the correct Javascript array. It doesn't matter if you clean the data at the data entry or escape/cleanse it when building output.
Hope it helps,
Dmitriy.
Listen up! "Teamwork" means staying out of my way! (Seifer, Final Fantasy 8).
|
|
|
|
|
|
Hi,
I have 3 autosuggest textboxs:
text1,text2,text3.
I need that if text1 or text2 was populated then text3 is enabled
and if both of them was erased text3 will be disable again.
I have tried the following code:
Event.observe('locationText', 'onkeydown', onKeyDownPress);
Event.observe('britText', 'onkeydown', onKeyDownPress);
function onKeyDownPress(event) {
var element = event.element();
var textLength = element.value.length;
if (textLength == 0) {
byLocationFlag = 0;
$('KMText').disabled = "disabled";
}
if (textLength > 0) {
byLocationFlag = 1;
$('KMText').disabled = '';
}
}
but when I select by going down on the list (with keyboard arrows) the event is not happenning.
what I did wrong?
|
|
|
|
|
hi When i am using this code only pre defined data is showing. I want to use asp textbox as input and array from my database. How can i do this.
waiting for your ans.
thanks
|
|
|
|