zapps's avatar
Level 8

Found 2 elements with non-unique id #password

Hi

I've upgraded Laravel 10 to 11 and also FilamentPHP to the latest version.

When i load the user profile page I get this error:

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

<input class=​"border-gray-300 dark:​border-gray-700 dark:​bg-gray-900 dark:​text-gray-300 focus:​border-indigo-500 dark:​focus:​border-indigo-600 focus:​ring-indigo-500 dark:​focus:​ring-indigo-600 rounded-md shadow-sm mt-1 block w-full" id=​"password" name=​"password" type=​"password" autocomplete=​"new-password">​

and

<input class="border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm mt-1 block w-3/4" id="password" name="password" type="password" placeholder="Password">

I understand the error. I can see the duplicates. Has anyone else experienced this after an upgrade?

This is happening to an out-of-the-box version of Laravel 10 and FilamentPHP. I haven't touched the laravel profile page at all.

Thanks

0 likes
1 reply
LaryAI's avatar
Level 58

The error you're encountering is due to having multiple HTML elements with the same id attribute, which should be unique within a page. This is a common issue that can arise when upgrading libraries or frameworks, as changes in the underlying code might introduce duplicate IDs.

To resolve this issue, you can take the following steps:

  1. Inspect the HTML: Use your browser's developer tools to inspect the HTML and identify where the duplicate id="password" attributes are being generated. This will help you understand if it's coming from a specific component or part of the page.

  2. Check Blade Templates: If you have custom Blade templates or components, ensure that you are not manually setting the id attribute to password in multiple places. If you find duplicates, consider using a unique identifier for each input.

  3. Review FilamentPHP Components: Since you mentioned using FilamentPHP, check if the components you are using have been updated in a way that might cause this duplication. Look for any configuration options or updates in the FilamentPHP documentation that might address this issue.

  4. Override IDs: If the duplicate IDs are coming from a third-party package or component that you cannot directly modify, consider overriding the IDs in your Blade templates or by using JavaScript to dynamically assign unique IDs after the page loads.

  5. Contact Support or Community: If the issue persists and you believe it's a bug introduced by the upgrade, consider reaching out to the FilamentPHP community or support channels. They might have more specific guidance or a patch available.

Here's an example of how you might dynamically assign unique IDs using JavaScript:

document.querySelectorAll('input[id="password"]').forEach((element, index) => {
    element.id = `password-${index}`;
});

This script will iterate over all input elements with the id="password" and assign them unique IDs by appending an index. However, use this as a temporary workaround and aim to fix the root cause in your templates or component configurations.

Please or to participate in this conversation.