Skip to content

fix(core): allow null/undefined values for required fields with defaults#2856

Open
cyphercodes wants to merge 1 commit intoteableio:developfrom
cyphercodes:fix/single-select-default-value
Open

fix(core): allow null/undefined values for required fields with defaults#2856
cyphercodes wants to merge 1 commit intoteableio:developfrom
cyphercodes:fix/single-select-default-value

Conversation

@cyphercodes
Copy link
Copy Markdown

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 validateCellValueWithNotNull in 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

  • Updated validateCellValueWithNotNull in packages/core/src/models/field/field.ts
  • Added check for options.defaultValue before returning validation error for null/undefined values

Testing

This fix ensures that:

  1. Required fields without defaults still reject null/undefined values
  2. Required fields with defaults allow null/undefined values (default will be applied later)
  3. Non-required fields continue to work as before

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
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 27, 2026

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Required "single select" field does not use default value

2 participants