[LiveComponent] Fix Allow empty values to bypass input model validation modifiers#3367
Open
xDeSwa wants to merge 1 commit intosymfony:2.xfrom
Open
[LiveComponent] Fix Allow empty values to bypass input model validation modifiers#3367xDeSwa wants to merge 1 commit intosymfony:2.xfrom
xDeSwa wants to merge 1 commit intosymfony:2.xfrom
Conversation
Contributor
📊 Packages dist files size differenceThanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
|
|||||||||
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.
The Problem:
Currently, when using input validation modifiers like
min_length(3)on a LiveComponent model (e.g.,<input type="search" data-model="min_length(3)|query" />), the modifier acts as a strict gatekeeper. If a user types "abc", the model updates correctly. However, if the user clears the input (e.g., by clicking the native "X" clear button on a search input or deleting the text), the update is blocked because the length is0.This creates a frustrating UX: the input appears empty on the screen, but the component fails to re-render or notify the server, leaving the page (and backend state) stuck with the previous search results.
The Solution:
This PR updates
LiveControllerto bypassmin_length,max_length,min_value, andmax_valuechecks if the input value is completely empty ('',null, orundefined).Why this is the correct approach (The HTML5 Standard):
This change aligns LiveComponent's frontend validation strictly with standard HTML5 form validation behavior. In HTML5, attributes like
minlengthandmindo not apply to empty values. If a field is allowed to be empty, it passes validation. If a field must not be empty, developers are expected to use therequiredattribute.By allowing empty strings to pass through these modifiers:
props:props.min_value) from casting an empty string to0and incorrectly failing validation.