Skip validation when csvValidate is false#1021
Closed
tagliala wants to merge 1 commit into
Closed
Conversation
Currently, the runtime only skips validation if the `data-csv-validate` attribute is missing. If it's explicitly set to `"false"`, the element is still included in the validation inputs because `"false" == null` is false. Change the check to ensure that only elements with `csvValidate` set to `"true"` are validated. This allows users to dynamically disable validation for specific elements by setting the attribute to `"false"`.
There was a problem hiding this comment.
Pull request overview
This PR changes the client-side-validations runtime so that form-level validation only runs for elements explicitly marked with data-csv-validate="true", allowing callers to skip validation by setting data-csv-validate="false" on specific elements.
Changes:
- Update
getValidationInputsto requireelement.dataset.csvValidate === 'true'(instead of only checking for null/undefined). - Add a QUnit regression test ensuring an input with
csvValidateset to"false"doesn’t block form submission. - Document the bugfix in the changelog and propagate the runtime change into distributed JS bundles.
Reviewed changes
Copilot reviewed 3 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| vendor/assets/javascripts/rails.validations.js | Applies the stricter data-csv-validate === "true" gating to the Rails vendor runtime bundle. |
| src/index.js | Updates the source implementation of getValidationInputs to validate only explicitly enabled inputs. |
| dist/client-side-validations.js | Updates the compiled UMD bundle to match the new validation gating behavior. |
| dist/client-side-validations.esm.js | Updates the compiled ESM bundle to match the new validation gating behavior. |
| test/javascript/public/test/form_builders/validateForm.js | Adds a regression test covering data-csv-validate="false" on submit. |
| CHANGELOG.md | Records the bugfix in the unreleased changelog section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const getValidationInputs = (form) => { | ||
| return Array.from(form.elements).filter((element) => { | ||
| if (element.dataset.csvValidate == null || element.disabled) { | ||
| if (element.dataset.csvValidate !== 'true' || element.disabled) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently, the runtime only skips validation if the
data-csv-validateattribute is missing. If it's explicitly set to"false", the element is still included in the validation inputs because"false" == nullis false.Change the check to ensure that only elements with
csvValidateset to"true"are validated. This allows users to dynamically disable validation for specific elements by setting the attribute to"false".