-
Notifications
You must be signed in to change notification settings - Fork 554
Expand file tree
/
Copy pathplugin.js
More file actions
59 lines (52 loc) · 2.37 KB
/
plugin.js
File metadata and controls
59 lines (52 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @class BtTooltipErrors
* @memberof module:plugins
* @description Applies Bootstrap Tooltips on validation error messages.
* @param {object} [options]
* @param {string} [options.placement='right']
* @throws MissingLibraryError
*/
QueryBuilder.define('bt-tooltip-errors', function(options) {
if (! typeof bootstrap.Tooltip === "function") {
alert(typeof bootstrap.Tooltip );
Utils.error('MissingLibrary', 'Bootstrap Popper is required to use "bt-tooltip-errors" plugin. Get it here: http://getbootstrap.com');
}
var self = this;
// add BT Tooltip data
this.on('getRuleTemplate.filter getGroupTemplate.filter', function(h) {
var $h = $($.parseHTML(h.value));
$h.find(QueryBuilder.selectors.error_container).attr('data-bs-toggle', 'tooltip');
h.value = $h.prop('outerHTML');
});
// init/refresh tooltip when title changes
this.model.on('update', function(e, node, field) {
if (field == 'error' && self.settings.display_errors) {
var $errorContainer = node.$el.find(QueryBuilder.selectors.error_container).eq(0);
// Translate the error message (node.error is an array like ['string_empty'])
var errorMessage = '';
if (node.error && Array.isArray(node.error) && node.error.length > 0) {
errorMessage = self.translate('errors', node.error[0]) || node.error[0] || '';
}
// Only set tooltip if we have a non-empty error message
if (errorMessage) {
$errorContainer.attr('data-bs-original-title', errorMessage).attr('data-bs-title', errorMessage);
// Initialize Bootstrap 5 tooltip (dispose existing first to avoid conflicts)
var tooltipEl = $errorContainer.get(0);
if (tooltipEl) {
// Dispose existing tooltip if any
var existingTooltip = bootstrap.Tooltip.getInstance(tooltipEl);
if (existingTooltip) {
existingTooltip.dispose();
}
// Create new tooltip with explicit title
new bootstrap.Tooltip(tooltipEl, {
placement: options.placement || 'right',
title: errorMessage
});
}
}
}
});
}, {
placement: 'right'
});