Custom form configuration #268

Merged
tobru merged 34 commits from 165-form-configuration into main 2025-11-10 14:49:33 +00:00
2 changed files with 31 additions and 0 deletions
Showing only changes of commit b3bb41b322 - Show all commits

View file

@ -144,6 +144,7 @@
value="{% if form_submit_label %}{{ form_submit_label }}{% else %}{% translate "Save" %}{% endif %}" />
</div>
</form>
<script defer src="{% static 'js/bootstrap-tabs.js' %}"></script>
{% if form %}
<script defer src="{% static 'js/expert-mode.js' %}"></script>
{% endif %}

30
src/servala/static/js/bootstrap-tabs.js vendored Normal file
View file

@ -0,0 +1,30 @@
// Bootstrap 5 automatically initializes tabs with data-bs-toggle="tab"
// but we need to ensure they work after HTMX swaps
(function() {
'use strict';
const initBootstrapTabs = () => {
const customTabList = document.querySelectorAll('#myTab button[data-bs-toggle="tab"]');
customTabList.forEach(function(tabButton) {
new bootstrap.Tab(tabButton);
});
const expertTabList = document.querySelectorAll('#expertTab button[data-bs-toggle="tab"]');
expertTabList.forEach(function(tabButton) {
new bootstrap.Tab(tabButton);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initBootstrapTabs);
} else {
initBootstrapTabs();
}
document.addEventListener('htmx:afterSwap', function(event) {
if (event.detail.target.id === 'service-form' ||
event.detail.target.classList.contains('crd-form')) {
initBootstrapTabs();
}
});
})();