Beating my head against a selector issue and hoping someone has some insight. Context is that I am developing a Mediawiki extension that is adding on some enterprise specific functionality to the edit page. Latest GA MediaWiki contains JQuery 1.11.3.
In this snippet, I am trying to add a section with a dynamically created table. Most of the code is working, so I have some confidence that JQuery is loading adequately in the environment. The selector leading up to the alert statement, which tries to find a text box if searchable, is not working. The text box does show up on the page and IE and Edge both show the ID as what is shown in comments. The selector always comes up with length zero. I wonder what I am missing. Is it the way I am handling various quote syntaxs? You can see I tried to simplify the "source" aspect by using an array source, rather than the JSON source I want to use, so use "Charl" as the test phrase if you try to test.
function addProviders(subjectType, data) {
var title = mw.config.get("wgTitle");
var html = '<div class="mw-portwizard-sourcelist" id = "mw-portwizard-sourcelist"></div>';
if (!$('#mw-portwizard-sourcelist').length) {
$(".templatesUsed").after (html);
}
html = '<div tabindex="0" id="mw-portwizard-sourcelistcontent" class="mw-editfooter-toggler mw-icon-arrow-expanded ui-widget" role="button"><p>Sources available for this page:</p></div>';
$('#mw-portwizard-sourcelist').html(html);
html = '<table id="mw-portwizard-sourcetable"><tbody></tbody></table>';
$('#mw-portwizard-sourcelistcontent').html(html);
var tbody = $("#mw-portwizard-sourcetable").children('tbody');
var table = tbody.length ? tbody : $("#mw-portwizard-sourcetable");
mw.log ("table:" + table);
//TODO: use jquery data to hold the type
//html += '<input type="hidden" value="' + type +'" name="mw-portwizard-sourcetype" id="mw-portwizard-sourcetype" />';
//TODO: Make this WORK!
$.each(data, function(index,value) {
var html = "<tr id='" + value.PortWizard.id +"-row'><td>" + value.PortWizard.url + "</td><td>" + (value.PortWizard.searchable ? '<input type="text" id="' + value.PortWizard.id +'-text" value="' + title + '">' : title) + "</td></tr>";
table.append(html);
if (value.PortWizard.searchable) {
$selector = "#" + value.PortWizard.id + "-text";
// $selector = "#en.wikipedia.org-text";en.wikipedia.org-text
$prompt = $selector + ":" + $($selector).length;
alert ($prompt);
$($selector).autocomplete({
/* source: function(request, response) {
new mw.Api().get( {
action: 'PortWizard',
provider: value.PortWizard.id,
subjectType: 'search',
query: request.term
}).done( function (data){
response(data);
});
},*/
source: ["Charles De Gaulle Airport", "Charlie Brown"],
minLength :3
});
});
}
html += "<button type=\"button\" onclick=\"getPageContent(event,'" + subjectType + "')\">Get Text</button>";
$('#mw-portwizard-sourcelist').append(html);
}
Thanks,
Jason