Sha256: 1daf60db25fa437d8f7f01e1dfce88884583a3018581e988027a89e2729f2d80
Contents?: true
Size: 1.11 KB
Versions: 3
Compression:
Stored size: 1.11 KB
Contents
import ApplicationController from './application_controller' import { Tab } from 'bootstrap' export default class extends ApplicationController { static values = { errorSelector: { type: String, default: '.is-invalid:not([type="hidden"])' } } connect () { this.element.querySelectorAll('.nav-link').forEach((link) => { this.updateErrorCount(link) }) this.focusFirstTabWithErrors() } updateErrorCount (link) { const pane = document.querySelector(link.getAttribute('href')) const errorCount = pane.querySelectorAll(this.errorSelectorValue).length if (errorCount > 0) { const badge = this._createErrorBadge(errorCount) link.appendChild(badge) } } focusFirstTabWithErrors () { this.element.querySelectorAll('.nav-link').forEach((link) => { if (link.querySelector('.badge-danger')) { Tab.getOrCreateInstance(link).show() return } }) } _createErrorBadge (count) { const badge = document.createElement('span') badge.classList.add('badge', 'badge-danger', 'badge-pill') badge.textContent = count return badge } }
Version data entries
3 entries across 3 versions & 1 rubygems