Fix broken select.js widget with tabular markup
The JS changes introduced in 2.244 caused several plugins that pre-populated select tags to stop working.
This was due to failing to locate a `.validation-error-area` node.
The solution is to introduce a fallback to handle this edge case
@@ -6,15 +6,31 @@ function updateListBox(listBox,url,config) {
var originalOnSuccess = config.onSuccess;
var l = $(listBox);
+ // Hacky function to retrofit compatibility with tables-to-divs
+ // If the <select> tag parent is a <td> element we can consider it's following a
+ // form entry using tables-to-divs markup.
+ function getStatusElement() {
+ function getStatusForTabularForms() {
+ return findFollowingTR(listBox, "validation-error-area").firstChild.nextSibling;
+ }
+ function getStatusForDivBasedForms() {
var settingMain = listBox.closest('.setting-main')
if (!settingMain) {
console.warn("Couldn't find the expected parent element (.setting-main) for element", listBox)
return;
}
- var status = settingMain.nextElementSibling;
+ return settingMain.nextElementSibling;
+ }
+
+ return listBox.parentNode.tagName === 'TD'
+ ? getStatusForTabularForms()
+ : getStatusForDivBasedForms();
+ }
+
+ var status = getStatusElement();
if (!status) {
- console.warn("Couldn't find the expected status element", settingMain)
+ console.warn("Couldn't find the expected status element")
return;
}
if (status.firstChild && status.firstChild.getAttribute('data-select-ajax-error')) {
