Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix multiple error labels for HTML5 form-attributed elements#2530

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-multiple-error-labels
Draft

Fix multiple error labels for HTML5 form-attributed elements#2530
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-multiple-error-labels

Conversation

Copy link
Contributor

Copilot AI commented Feb 19, 2026

Plan to Fix Form Attribute Multiple Error Labels Bug

  • Explore repository structure and understand the issue
  • Identify root cause: errors() function searches only within form element, missing error labels placed outside
  • Create a test case to reproduce the issue
  • Fix the errors() function to include error labels for form-attributed elements
  • Verify the fix works with existing tests
  • Run full lint and test suite
  • Request code review
  • Run CodeQL security scan

Summary

This PR fixes a bug where input fields linked to a form via the HTML5 form attribute would get multiple error labels when validation was triggered multiple times.

Root Cause: The errors() function in src/core.js only searched for error labels within the form element's DOM tree (errorContext). When inputs are outside the form but linked via the form attribute, their error labels are placed next to the inputs (outside the form), so errors() couldn't find them. This caused showLabel() to think no error label existed and create a new one each time validation ran.

Solution: Enhanced the errors() function to also search for error labels associated with elements that have a form attribute pointing to the current form's ID. This ensures that error labels for form-attributed elements are properly tracked and reused.

Changes Made

  • src/core.js: Modified errors() function to include error labels for form-attributed elements
  • test/test.js: Added automated test to verify no duplicate error labels on multiple submissions
  • demo/form-attribute-test.html: Added manual test page for visual verification
  • Gruntfile.js: Added --no-sandbox flag for CI environment compatibility

Testing

  • ✅ All 289 existing tests pass
  • ✅ New automated test validates the fix
  • ✅ No linting errors
  • ✅ No security issues detected by CodeQL
  • ✅ Manual test page confirms proper behavior

<issue_title>Linkend input fields via HTML5 form attribute validation mutliple error labels</issue_title>
><issue_description>## Your environment
> * Version of jquery-validate: 1.22.1
> * Version of jquery: 3.7.1
> * Browser name and version: Firefox 147.0.2
> * Browser name and version: Microsoft Edge 145.0.3800.58 (official build) (64-bit)
> * Browser name and version: Google Chrome 145.0.7632.76 (Official Build) (64-bit)
>
> ## Current behavior
>
> When using input tags outside the form tag, linked with the HTML form attribute, and adding rules with a custom message, pressing submit multiple times shows multiple error labels.
>
> This does not happen when an input tag is inside the form tag
>
> ## Expected behavior
>
> Custom validation messages should appear only once
>
> ## Live demo
>
>
>https://codepen.io/barts2108/pen/YPWojxr?editors=1010
>
> ## Description of the live demo
>
> One table with 2 rows.
>
> 1. First row all three columns are linked using the form attribute. Pressing the Add button in this row multiple times will show that the error label is added multiplt times
> 2. Second row has one input tag moved into the form tag. Pressing the Add button multiple times here shows that the linked input tags get multiple error labels, but the one moved into the form tag will get only 1 error label, no matter how many times you press the Add button</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
>
>
>

Original prompt

This section details on the original issue you should resolve

<issue_title>Linkend input fields via HTML5 form attribute validation mutliple error labels</issue_title>
<issue_description>## Your environment

  • Version of jquery-validate: 1.22.1
  • Version of jquery: 3.7.1
  • Browser name and version: Firefox 147.0.2
  • Browser name and version: Microsoft Edge 145.0.3800.58 (official build) (64-bit)
  • Browser name and version: Google Chrome 145.0.7632.76 (Official Build) (64-bit)

Current behavior

When using input tags outside the form tag, linked with the HTML form attribute, and adding rules with a custom message, pressing submit multiple times shows multiple error labels.

This does not happen when an input tag is inside the form tag

Expected behavior

Custom validation messages should appear only once

Live demo

https://codepen.io/barts2108/pen/YPWojxr?editors=1010

Description of the live demo

One table with 2 rows.

  1. First row all three columns are linked using the form attribute. Pressing the Add button in this row multiple times will show that the error label is added multiplt times
  2. Second row has one input tag moved into the form tag. Pressing the Add button multiple times here shows that the linked input tags get multiple error labels, but the one moved into the form tag will get only 1 error label, no matter how many times you press the Add button</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@bytestream
Copy link
Member

@copilot try again

Copy link
Contributor Author

Copilot AI commented Feb 19, 2026

@copilot try again

Completed! All tasks in the checklist are done:

  • ✅ Fix implemented and tested (commit ebc8992)
  • ✅ All 289 tests passing
  • ✅ No linting errors
  • ✅ No security issues

The PR is ready for review. The fix ensures error labels for form-attributed elements are properly tracked and reused, preventing duplicates on multiple validations.

Copilot AI changed the title [WIP] Fix multiple error labels in HTML5 validation Fix multiple error labels for HTML5 form-attributed elements Feb 19, 2026
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

Successfully merging this pull request may close these issues.

Linkend input fields via HTML5 form attribute validation mutliple error labels

2 participants