I am trying to overwrite a function in jquery ui autocomplete.
When i do
$.ui.autocomplete.prototype._create = function() { var self = this, doc = this.element[ 0 ].ownerDocument, suppressKeyPress; this._value( ... ) ;
I get this._value undefined error.
I know that this context is confused. How to fix it?
I am trying to use $.proxy , but then I do not know how to refer to the initial closing context of $.ui.autocomplete .
EDIT:
Ok, let me break it. I want to edit jquery autocomplete so that when a user clicks on user-generated content, he simply ignores it, and does not enter it.
The original question comes from this: JQuery autocomplete. If the item is not found, display "Press Enter to paste into autocomplete"?
So let's break the questions:
I am expanding this function:
$.ui.autocomplete.prototype._create = function() { console.log(this, $.ui.autocomplete); var self = this, doc = this.element[ 0 ].ownerDocument, suppressKeyPress; this.valueMethod = this.element[ this.element.is( "input" ) ? "val" : "text" ]; this.element .addClass( "ui-autocomplete-input" ) .attr( "autocomplete", "off" ) // TODO verify these actually work as intended .attr({ role: "textbox", "aria-autocomplete": "list", "aria-haspopup": "true" }) .bind( "keydown.autocomplete", function( event ) { if ( self.options.disabled || self.element.attr( "readonly" ) ) { return; } suppressKeyPress = false; var keyCode = $.ui.keyCode; switch( event.keyCode ) { case keyCode.PAGE_UP: self._move( "previousPage", event ); break; case keyCode.PAGE_DOWN: self._move( "nextPage", event ); break; case keyCode.UP: self._move( "previous", event ); // prevent moving cursor to beginning of text field in some browsers event.preventDefault(); break; case keyCode.DOWN: self._move( "next", event ); // prevent moving cursor to end of text field in some browsers event.preventDefault(); break; case keyCode.ENTER: case keyCode.NUMPAD_ENTER: // when menu is open and has focus if ( self.menu.active ) { //
which is directly copied from jquery.ui.autcomplete.js
For your convenience, jquery autocomplete is found https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.autocomplete.js