fix: align dependent element logic with server-side behaviour #1062
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this achieve?
This change ensures that the last input element with a given name is used when evaluating dependencies in custom validation logic.
This is important because, in HTML form submissions, the last matching input with the same name takes precedence when there are multiple inputs with the same name. A common example is when using a hidden input alongside a checkbox to provide a default value:
This pattern is widely used to ensure a consistent value is submitted whether the checkbox is checked or not. If the checkbox is unchecked, only the hidden input (value="0") is submitted. If it is checked, both are submitted, but the checkbox value (1) takes precedence.
Without this fix, the validation logic incorrectly evaluates the first input (the hidden one), ignoring the actual user interaction with the checkbox. By using the last matching input, we align the validation behavior with how browsers and backends (like Laravel) interpret the submitted data.