Skip to content

Commit 9a5ccb4

Browse files
committed
Sync tom-select init scripts from CRP Pro
1 parent 7f4388b commit 9a5ccb4

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

includes/admin/settings/js/tom-select-init.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
return;
4949
}
5050

51+
const tagName = (element.tagName || '').toUpperCase();
52+
if (tagName !== 'INPUT' && tagName !== 'SELECT' && tagName !== 'TEXTAREA') {
53+
return;
54+
}
55+
5156
const prefix = element.getAttribute('data-wp-prefix') || 'WZ';
5257
const settingsKey = `${prefix}TomSelectSettings`;
5358
const settings = window[settingsKey]
@@ -66,7 +71,21 @@
6671

6772
const formattedOptions = getEndpointOptions(settings, endpoint);
6873

69-
const savedIds = element.value.split(',').map(id => id.trim()).filter(Boolean);
74+
let rawValue = '';
75+
76+
if (tagName === 'SELECT' && element.multiple && element.selectedOptions) {
77+
rawValue = Array.from(element.selectedOptions)
78+
.map(option => String(option.value || '').trim())
79+
.filter(Boolean)
80+
.join(',');
81+
} else if (typeof element.value === 'string') {
82+
rawValue = element.value;
83+
} else {
84+
const valueAttribute = element.getAttribute('value');
85+
rawValue = typeof valueAttribute === 'string' ? valueAttribute : '';
86+
}
87+
88+
const savedIds = rawValue.split(',').map(id => id.trim()).filter(Boolean);
7089
const taxonomyEndpoint = isTaxonomyEndpoint(endpoint);
7190

7291
// For taxonomy endpoints, add saved values as options so Tom Select can display them

includes/admin/settings/js/tom-select-init.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)