fabiomcosta / mootools-meio-autocomplete

A complete mootools Autocomplete plugin
http://www.meiocodigo.com/projects/meio-autocomplete/
32 stars 14 forks source link

Complete text of item does not fire update event #9

Closed collosi closed 11 years ago

collosi commented 13 years ago

If you use an Autocomplete.Select, and type the full text of one of the items, then tab out of the field, the value field will not be set.

In this example type asdf and tab, note that the value in the second field does not get set.

http://jsfiddle.net/j37Ny/7/

If you type asdf, then click the selection the second field will get set.

collosi commented 13 years ago

Would this patch do the trick?


diff --git a/Source/Meio.Autocomplete.js b/Source/Meio.Autocomplete.js
index be27442..df9e89e 100644
--- a/Source/Meio.Autocomplete.js
+++ b/Source/Meio.Autocomplete.js
@@ -223,6 +223,7 @@ provides: [Meio.Autocomplete]
                                                if (list.focusedItem) list.hide();
                                        } else {
                                                list.hide();
+                                               this.setTypedInputValue();
                                        }
                                },
                                'paste': function(){
@@ -303,6 +304,19 @@ provides: [Meio.Autocomplete]
                        }
                },

+               setTypedInputValue: function(){
+                       var data = this.data.get();
+                       var text = this.inputedText;
+                       for (var i = 0; i < data.length; i++) { 
+                               var formatted = this.filters.formatMatch.call(this, text, data[i]);
+                               if (text === formatted) {
+                                       this.fireEvent('select', [this.elements, data[i], text, i]);
+                                       return
+                               }
+                       }
+               },
+        
+               
                setInputValue: function(){
                        var list = this.elements.list;
                        if (list.focusedItem){