wordpress - jQuery Autocomplete input clears itself -
I am using jQuery autocloplets in a WordPress custom post. When filling the autocomplete input field, AJAX works correctly, and returns matching data. Once I select an item in the drop-down list, the input field clears itself. I went through the javascript step by step, and the input field #title populateForm () function is set correctly , But after the end of my script the field is empty at some point.
Does anyone know that this may be the reason, or can I work around it in a decent way?
I have given my JS down. I have any other information that can help tell me.
(function ($) {var url = ajax_object.ajaxurl; var popped = [] $ ('# title'). Autocomplete ({source: function (request, response) {$. GetJSON (url, {term: extractLlast (request.term, verb: 'autocomplete'}, response);}, search: work () {var term = extractLast (this. (Value), if (term.length & lt ; 2) Select {return false}}} function (Event, UI) {populateForm (ui.item);}, Reaction: Function (Event, UI) {for (var i ui.content) {popped. Gt; "). Data (" ui-autocomplete-item ", item) .append (" & lt; a & gt; & lt; strong & gt; "+ Item.name + "& lt; / strong> (" + Item.username.replace (/ [a-zA-Z] + / g, '') + ") ) .appendTo (ul);}; function populateForm (obj) {$ (Obj.hasOwnProperty (property)) {$ ('input # form-' + property) .val ('input # title'). Val (obj [ 'Username']) for obj (var property obj [property]);}}} function split (val) {return valple split (/, \ s * /);} function extract list (term) {return split (Term). Pop ();}}) (jQuery);
, select
event's ui .item
has only 2 attributes: label
and value
. You are sending it to populateForm ()
and then the value of the text input for your ui.item.username
. If you open your browser's Dev console, you should see an error.
Comments
Post a Comment