fix(core): allow null/undefined values for required fields with defaults#2856
Open
cyphercodes wants to merge 1 commit intoteableio:developfrom
Open
fix(core): allow null/undefined values for required fields with defaults#2856cyphercodes wants to merge 1 commit intoteableio:developfrom
cyphercodes wants to merge 1 commit intoteableio:developfrom
Conversation
When a field is required (notNull) but has a default value defined, null or undefined inputs should be allowed to pass through validation since the default value will be applied later in the record creation process. Fixes teableio#2771
|
|
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
When a field is required (notNull) and has a default value, creating a new record without explicitly providing a value for that field would fail validation with a 'Required' error. This happened because the validation logic didn't account for the fact that a default value would be applied later in the record creation process.
Fixes #2771
Solution
Modified
validateCellValueWithNotNullin the FieldCore class to check if the field has a default value before rejecting null/undefined inputs. If a default value is defined, the validation allows null/undefined to pass through, since the default will be applied later.Changes
validateCellValueWithNotNullinpackages/core/src/models/field/field.tsoptions.defaultValuebefore returning validation error for null/undefined valuesTesting
This fix ensures that: