mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-26 04:28:39 +02:00
Test making button clickable
This commit is contained in:
parent
3a12e59db6
commit
0e09e5720b
4 changed files with 26 additions and 1 deletions
16
src/registrar/assets/src/js/getgov-admin/button-utils.js
Normal file
16
src/registrar/assets/src/js/getgov-admin/button-utils.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/**
|
||||||
|
* Initializes buttons to behave like links by navigating to their data-url attribute
|
||||||
|
* Example usage: <button class="use-button-as-link" data-url="/some/path">Click me</button>
|
||||||
|
*/
|
||||||
|
export function initButtonLinks() {
|
||||||
|
document.querySelectorAll('button.use-button-as-link').forEach(button => {
|
||||||
|
button.addEventListener('click', function() {
|
||||||
|
// Equivalent to button.getAttribute("data-href")
|
||||||
|
const href = this.dataset.href;
|
||||||
|
console.log(`in loop: ${href}`)
|
||||||
|
if (href) {
|
||||||
|
window.location.href = href;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ import { initDynamicPortfolioFields } from './portfolio-form.js';
|
||||||
import { initDynamicDomainInformationFields } from './domain-information-form.js';
|
import { initDynamicDomainInformationFields } from './domain-information-form.js';
|
||||||
import { initDynamicDomainFields } from './domain-form.js';
|
import { initDynamicDomainFields } from './domain-form.js';
|
||||||
import { initAnalyticsDashboard } from './analytics.js';
|
import { initAnalyticsDashboard } from './analytics.js';
|
||||||
|
import { initButtonLinks } from './button-utils.js';
|
||||||
|
|
||||||
// General
|
// General
|
||||||
initModals();
|
initModals();
|
||||||
|
@ -23,6 +24,7 @@ initCopyToClipboard();
|
||||||
initFilterHorizontalWidget();
|
initFilterHorizontalWidget();
|
||||||
initDescriptions();
|
initDescriptions();
|
||||||
initSubmitBar();
|
initSubmitBar();
|
||||||
|
initButtonLinks();
|
||||||
|
|
||||||
// Domain request
|
// Domain request
|
||||||
initIneligibleModal();
|
initIneligibleModal();
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
{% load i18n %}
|
||||||
|
{% load admin_urls %}
|
||||||
|
|
||||||
|
{% if has_export_permission %}
|
||||||
|
{% comment %} Uses the initButtonLinks {% endcomment %}
|
||||||
|
<li><button class="export_link use-button-as-link" data-href="{% url opts|admin_urlname:"export" %}">{% trans "Export" %}</button></li>
|
||||||
|
{% endif %}
|
|
@ -3,6 +3,6 @@
|
||||||
|
|
||||||
{% if has_import_permission %}
|
{% if has_import_permission %}
|
||||||
{% if not IS_PRODUCTION %}
|
{% if not IS_PRODUCTION %}
|
||||||
<li><a href='{% url opts|admin_urlname:"import" %}' class="import_link">{% trans "Import" %}</a></li>
|
<li><button class="import_link use-button-as-link" data-href="{% url opts|admin_urlname:"import" %}">{% trans "Import" %}</button></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue