fix: prevent self-clear of field_code in visibility condition repeater#146
Open
erikpach wants to merge 1 commit intorelaticle:3.xfrom
Open
fix: prevent self-clear of field_code in visibility condition repeater#146erikpach wants to merge 1 commit intorelaticle:3.xfrom
erikpach wants to merge 1 commit intorelaticle:3.xfrom
Conversation
Selecting a value in the 'field_code' Select inside the visibility conditions Repeater triggered an afterStateUpdated callback that called resetConditionValues(), which itself sets field_code to null. The just selected value was wiped immediately, so users could not configure conditions. Split the reset into two operations: - resetConditionValues() (used by source change) clears field_code, values, and operator. - resetValuesAndOperator() (used by field_code change) only clears the value fields and updates the default operator, preserving the user selected field_code.
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.
Summary
Fixes a bug in the visibility conditions UI for custom fields where selecting a value in the Field (
field_code) Select inside the conditions Repeater immediately clears the selection.Reproduction
The bug also affects the
ConditionSource::ModelAttributesource where the dropdown of model attributes appears, gets selected, and disappears.Root cause
src/Filament/Management/Forms/Components/VisibilityComponent.phpline 127:resetConditionValues()is shared with thesourceSelect and contains:So when the user picks
field_code, Filament firesafterStateUpdated, which setsfield_codeback tonull.Fix
Split the reset path:
resetConditionValues()keeps its current behavior and remains the callback for thesourceSelect (it should clearfield_codewhen the source switches).resetValuesAndOperator()is used by thefield_codeSelect. It only clears the value fields and resets the operator to the first compatible option. It does not touchfield_code.Verification