fix: Number component incorrectly uses label as validator key#495
Merged
nie7321 merged 1 commit intoApr 16, 2026
Conversation
…rs on optional fields
dxnter
approved these changes
Apr 16, 2026
dxnter
left a comment
Member
There was a problem hiding this comment.
Thanks!
I think CI is misconfigured for forks, but I've verified that tests are passing
45e3a8a
into
NIT-Administrative-Systems:develop
1 of 4 checks passed
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.
Problem
The
Numbercomponent'sprocessValidationsmethod overwrites the$fieldKeyparameter with the component's label string:
$fieldKey = $this->label() ?? $this->key();This means the validator's data array is keyed by the label (e.g. "Wash Temp")
instead of the actual FormIO field key (e.g. washTemp).
When a user submits an empty optional number field, submissionValue() returns
null. Laravel's Arr::has finds the label-key directly in the data (since it
contains no dots), so the numeric rule fires on null, producing a spurious
validation error: "The Wash Temp must be a number."
Odd side effect: Labels ending with a dot (e.g. "Rinse Temp.") happen to
avoid the error — Laravel's Arr::has treats dots as nested key separators, so it
looks for data["Rinse Temp"][""] which doesn't exist, and the numeric rule
never fires. This made the bug appear inconsistent and hard to trace.
Fix
Two changes, modelled after the existing Currency component which handles this
correctly:
BaseComponent::validate(), which is already $this->key().
does not trigger the numeric rule (same pattern as Currency).
Tests
Added two cases to NumberTest::validationsProvider() covering empty optional
fields (both null and empty string).