[Proto-Scripty] Re: Autocomplete : make not automatically select first item

2008-10-22 Thread luniki

You could fork the official scriptaculous git repository at github
(http://github.com/madrobby/scriptaculous/tree/master), patch it and
send a pull request to madrobby. I like your patch and would vote +1
if necessary :-)


On Oct 20, 3:00 pm, Jesper Rønn-Jensen <[EMAIL PROTECTED]> wrote:
> Thanks for your really helpful advice.
>
> I turned your suggestion into the following patch and also modified
> the Rails auto_complete helper as well.
> (the revision numbers unfortunately point at my local application
> where I made the modification).
>
> If you find this helpful, could you help me getting this committed
> into the proper projects? :)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Autocomplete : make not automatically select first item

2008-10-22 Thread doofus

thanks for the tip guys.

Setting the index to -1 works, but i get the following error when I
actually hit enter to submit the form (the form does submit though,
but I can see the error):

Index or size is negative or greater than the allowed amount" code: "1

on this line:

 return this.update.firstChild.childNodes[index];

in:
controls.js (line 228 for me)

I tracked it down to the onkeypress event and what is triggered when
you hit ENTER. this triggers the selectEntry method which calls
updateElement(this.getCurrentEntry()), and of course there is no
current entry ...

replacing the contents of selectEntry with this seemed to work:
if(this.index != -1){
this.updateElement(this.getCurrentEntry());
}

but if you use afterUpdateElement for any additional processing, this
will not run because it is called within updateElement.

so until somebody fixes this (because this is a ugly hack), I modified
selectEntry to this:

  selectEntry: function() {
this.active = false;
if(this.index != -1){
this.updateElement(this.getCurrentEntry());
}else{
if (this.options.afterUpdateElement)
this.options.afterUpdateElement(this.element, new Element('li',
{id: '', name: ''}));
}
  }


On Oct 20, 6:00 am, Jesper Rønn-Jensen <[EMAIL PROTECTED]> wrote:
> Thanks for your really helpful advice.
>
> I turned your suggestion into the following patch and also modified
> the Rails auto_complete helper as well.
> (the revision numbers unfortunately point at my local application
> where I made the modification).
>
> If you find this helpful, could you help me getting this committed
> into the proper projects? :)
> Thanks!
>
> /Jesper Rønn-Jensen
> Bloghttp://justaddwater.dk/
>
> --
> Index: vendor/plugins/auto_complete/README
> ===
> --- vendor/plugins/auto_complete/README (revision 878)
> +++ vendor/plugins/auto_complete/README (working copy)
> @@ -20,4 +20,6 @@
>  *http://script.aculo.us/demos/ajax/autocompleter
>  *http://script.aculo.us/demos/ajax/autocompleter_customized
>
> +* Autocompleter URL:http://github.com/rails/auto_complete/
> +
>  Copyright (c) 2007 David Heinemeier Hansson, released under the MIT
> license
> Index: vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb
> ===
> --- vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb
> (revision 878)
> +++ vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb
> (working copy)
> @@ -55,6 +55,9 @@
>    #                                  the entire element is used.
>    # :method::               Specifies the HTTP verb to use
> when the autocompletion
>    #                                  request is made. Defaults to
> POST.
> +  # :auto_select_first::    Toggle auto selection of first
> item found in autocompleter.
> +  #                                  'true'~=mac style, 'false'~=pc
> style
> +  #                                  (defaults to true)
>    def auto_complete_field(field_id, options = {})
>      function =  "var #{field_id}_auto_completer = new
> Ajax.Autocompleter("
>      function << "'#{field_id}', "
> @@ -62,15 +65,16 @@
>      function << "'#{url_for(options[:url])}'"
>
>      js_options = {}
> -    js_options[:tokens] =
> array_or_string_for_javascript(options[:tokens]) if options[:tokens]
> -    js_options[:callback]   = "function(element, value) { return
> #{options[:with]} }" if options[:with]
> -    js_options[:indicator]  = "'#{options[:indicator]}'" if
> options[:indicator]
> -    js_options[:select]     = "'#{options[:select]}'" if
> options[:select]
> -    js_options[:paramName]  = "'#{options[:param_name]}'" if
> options[:param_name]
> -    js_options[:frequency]  = "#{options[:frequency]}" if
> options[:frequency]
> -    js_options[:method]     = "'#{options[:method].to_s}'" if
> options[:method]
> +    js_options[:tokens]          =
> array_or_string_for_javascript(options[:tokens]) if options[:tokens]
> +    js_options[:callback]        = "function(element, value) { return
> #{options[:with]} }" if options[:with]
> +    js_options[:indicator]       = "'#{options[:indicator]}'" if
> options[:indicator]
> +    js_options[:select]          = "'#{options[:select]}'" if
> options[:select]
> +    js_options[:paramName]       = "'#{options[:param_name]}'" if
> options[:param_name]
> +    js_options[:frequency]       = "#{options[:frequency]}" if
> options[:frequency]
> +    js_options[:method]          = "'#{options[:method].to_s}'" if
> options[:method]
> +    js_options[:autoSelectFirst] =
> "'#{options[:auto_select_first].to_s}'" || "true"
>
> -    { :after_update_element => :afterUpdateElement,
> +    { :after_update_element => :afterUpdateElement,
>        :on_show => :onShow, :on_hide => :onHide, :min_chars
> => :minChars }.each do |k,v|
>        js_options[v] = options[k] if options[k]
>      end
> Index: public/javascripts/cont

[Proto-Scripty] Re: Autocomplete : make not automatically select first item

2008-10-20 Thread Jesper Rønn-Jensen

Thanks for your really helpful advice.

I turned your suggestion into the following patch and also modified
the Rails auto_complete helper as well.
(the revision numbers unfortunately point at my local application
where I made the modification).

If you find this helpful, could you help me getting this committed
into the proper projects? :)
Thanks!

/Jesper Rønn-Jensen
Blog http://justaddwater.dk/

--
Index: vendor/plugins/auto_complete/README
===
--- vendor/plugins/auto_complete/README (revision 878)
+++ vendor/plugins/auto_complete/README (working copy)
@@ -20,4 +20,6 @@
 * http://script.aculo.us/demos/ajax/autocompleter
 * http://script.aculo.us/demos/ajax/autocompleter_customized

+* Autocompleter URL: http://github.com/rails/auto_complete/
+
 Copyright (c) 2007 David Heinemeier Hansson, released under the MIT
license
Index: vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb
===
--- vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb
(revision 878)
+++ vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb
(working copy)
@@ -55,6 +55,9 @@
   #  the entire element is used.
   # :method::   Specifies the HTTP verb to use
when the autocompletion
   #  request is made. Defaults to
POST.
+  # :auto_select_first::Toggle auto selection of first
item found in autocompleter.
+  #  'true'~=mac style, 'false'~=pc
style
+  #  (defaults to true)
   def auto_complete_field(field_id, options = {})
 function =  "var #{field_id}_auto_completer = new
Ajax.Autocompleter("
 function << "'#{field_id}', "
@@ -62,15 +65,16 @@
 function << "'#{url_for(options[:url])}'"

 js_options = {}
-js_options[:tokens] =
array_or_string_for_javascript(options[:tokens]) if options[:tokens]
-js_options[:callback]   = "function(element, value) { return
#{options[:with]} }" if options[:with]
-js_options[:indicator]  = "'#{options[:indicator]}'" if
options[:indicator]
-js_options[:select] = "'#{options[:select]}'" if
options[:select]
-js_options[:paramName]  = "'#{options[:param_name]}'" if
options[:param_name]
-js_options[:frequency]  = "#{options[:frequency]}" if
options[:frequency]
-js_options[:method] = "'#{options[:method].to_s}'" if
options[:method]
+js_options[:tokens]  =
array_or_string_for_javascript(options[:tokens]) if options[:tokens]
+js_options[:callback]= "function(element, value) { return
#{options[:with]} }" if options[:with]
+js_options[:indicator]   = "'#{options[:indicator]}'" if
options[:indicator]
+js_options[:select]  = "'#{options[:select]}'" if
options[:select]
+js_options[:paramName]   = "'#{options[:param_name]}'" if
options[:param_name]
+js_options[:frequency]   = "#{options[:frequency]}" if
options[:frequency]
+js_options[:method]  = "'#{options[:method].to_s}'" if
options[:method]
+js_options[:autoSelectFirst] =
"'#{options[:auto_select_first].to_s}'" || "true"

-{ :after_update_element => :afterUpdateElement,
+{ :after_update_element => :afterUpdateElement,
   :on_show => :onShow, :on_hide => :onHide, :min_chars
=> :minChars }.each do |k,v|
   js_options[v] = options[k] if options[k]
 end
Index: public/javascripts/controls.js
===
--- public/javascripts/controls.js  (revision 883)
+++ public/javascripts/controls.js  (working copy)
@@ -40,14 +40,15 @@
 var Autocompleter = { }
 Autocompleter.Base = Class.create({
   baseInitialize: function(element, update, options) {
-element  = $(element)
-this.element = element;
-this.update  = $(update);
-this.hasFocus= false;
-this.changed = false;
-this.active  = false;
-this.index   = 0;
-this.entryCount  = 0;
+element  = $(element)
+this.element = element;
+this.update  = $(update);
+this.hasFocus= false;
+this.changed = false;
+this.active  = false;
+this.index   = 0;
+this.entryCount  = 0;
+this.autoSelectFirst = 'true';//toggle auto selection of first
item found in autocompleter.'true'~=mac, 'false'~=pc
 this.oldElementValue = this.element.value;

 if(this.setOptions)
@@ -55,11 +56,12 @@
 else
   this.options = options || { };

-this.options.paramName= this.options.paramName ||
this.element.name;
-this.options.tokens   = this.options.tokens || [];
-this.options.frequency= this.options.frequency || 0.4;
-this.options.minChars = this.options.minChars || 1;
-this.options.onShow   = this.options.onShow ||
+this.options.paramName   = t