Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Found 2 elements with non-unique id #logout-form #67

Open
ser-tec opened this issue May 21, 2024 · 2 comments
Open

Found 2 elements with non-unique id #logout-form #67

ser-tec opened this issue May 21, 2024 · 2 comments

Comments

@ser-tec
Copy link
Contributor

ser-tec commented May 21, 2024

settings:1 [DOM] Found 2 elements with non-unique id #logout-form: (More info: https://goo.gl/9p2vKq) <form id=​"logout-form" action=​"http:​/​/​dashboard.test/​logout" method=​"POST" style=​"display:​ none;​">​…​​ <form id=​"logout-form" action=​"http:​/​/​dashboard.test/​logout" method=​"POST" style=​"display:​ none;​">​…​​

@takielias
Copy link
Owner

@ser-tec I did not get the issue. Could you please explain?

@ser-tec
Copy link
Contributor Author

ser-tec commented Dec 5, 2024

Issue Title

Duplicate id="logout-form" issue in "combo" layout mode (top-right.blade.php)


Issue Description

Hello,

I've encountered an issue where the id="logout-form" is duplicated when using the "combo" layout mode and top-right.blade.php is included in multiple places within the application (e.g., in both sidebar.blade.php and sidebar-top.blade.php). This results in a non-unique ID error in the browser console:

[DOM] Found 2 elements with non-unique id #logout-form: (More info: https://goo.gl/9p2vKq)

Steps to Reproduce

  1. Enable the "combo" layout mode in the Tablar configuration:
    'layout' => 'combo',
  2. Load the page and inspect the console for the error.

Current Behavior

The id="logout-form" is hardcoded in top-right.blade.php, leading to duplicate IDs in the DOM when the layout mode is set to "combo".


Expected Behavior

Each instance of the logout form should have a unique ID to comply with HTML specifications and avoid browser console errors.


Proposed Solution

To resolve this issue, modify the top-right.blade.php file to dynamically generate a unique ID for the logout form. For example, use uniqid() to ensure uniqueness:

Updated top-right.blade.php:

<form id="logout-form-{{ uniqid() }}" action="{{ $logout_url }}" method="POST" style="display: none;">
    @if(config('tablar.logout_method'))
        {{ method_field(config('tablar.logout_method')) }}
    @endif
    {{ csrf_field() }}
</form>

And update the logout link to use the dynamically generated ID:

<a class="dropdown-item"
   href="#" onclick="event.preventDefault(); document.getElementById('logout-form-{{ uniqid() }}').submit();">
    <i class="fa fa-fw fa-power-off text-red"></i>
    {{ __('tablar::tablar.log_out') }}
</a>

Why This Matters

don't know if it matter but i don't like to see console error


Environment

  • Laravel Version: 11.x
  • Tablar Version: Latest (as of today)
  • Livewire Version: 3.x
  • PHP Version: 8.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants