I am trying to change lowercase letters to uppercase, while the user is typing in the input field. After that, the value of the input field will be used as a keyword for the typeahhead search engine.
The problem is, when I add an Event Listener to TypeAhead, the input value is changing to both uppercase and lowercase of the typing letter. $ (Document) .ready (function (= {"Audi", "Porsche", "Pagny", "Mercedes Benz", "BMW", "Bugatti"]; var descs = New Bloodhound ({datumTokenizer: Bloodhound.tokenizers.obj.whitespace ('value'), queryTranslator: Bloodhound.tokenizers.whitespace, local: $ .map (suggestion, function (desc) {return} {value: desc};})}); var quicksearchInput = $ ("# In"); // prevents the loading / processing of `local` and 'prefetch' descs.initialize (); QuicksearchInput.on ('keypress', function event) {var val = this.value; event = Event || window.event; var charCode = typeof event.which == "number"? Event.which: event.keyCode; if ( CharCode & Charcoda! = 13 & amp; amp; & amp; amp; amp; amp; & amp; amp; amp; amp; & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; and & # 8; Charcoda! = 8) {var keyChar = String.fromCharCode (charCode) ToUpperCase (); Var mapped key = key; Var start, end; if (select this type. Select: == "number" and thus. Selection == "number") {start = this.selectionStart; end = This.selectionEnd; This.value = val.slice (0, start) + mapped + val.slice (end); This.selectionStart = this.selectionEnd = start + 1; $ ("#debikar"). Tykehead ('val', this.value); }}}}. Template: {empty: ['& lt; Div class = "empty-message" & gt; ',' No matching results found '', '& lt; / Div & gt; '] Insert ('\ n')}}); });
I found a solution to my problem Removed the event handler, added the custom source function and manipulated the query variable to change the letters in uppercase for typed head.
$ (document) .ready (function () {var suggestionsArray = ["Audi", "Porsche", "Pagani", "Mercedes Benz", "BMW", "Bugatti"] ; Var descs = new bluehound ({DataTokinator: bloodhound.tokenizers.obj.whitespace ('value'), QueryTokenizer: bloodhound.tokenizers.whitespace, local: $ .map (suggestionAir, function (desc) {return} {value: desc };}}}); Var quicksearchInput = $ ("# in"); // Stop loading / `local` and 'prefetch' processing / descs.initialize (); QuicksearchInput.typeahead ({sign: true, highlight: True, Minlemmie: {}, {name: "name", of the display: "value", source: f (Query, CB) {query = query.toUpperCase (); $ ("# in" , 5));}}}, temp Lates: {empty: [div class = "empty-message">, 'no matching results found' ',' ]] ('\ N')}}}}}; The solution is here
No comments:
Post a Comment