Skip to content

fix(#691): bind invalid values as empty strings#700

Open
garethbowen wants to merge 4 commits intomainfrom
691-dont-error-on-invalid-values
Open

fix(#691): bind invalid values as empty strings#700
garethbowen wants to merge 4 commits intomainfrom
691-dont-error-on-invalid-values

Conversation

@garethbowen
Copy link
Collaborator

Closes #691

I have verified this PR works in these browsers (latest versions):

  • Chrome
  • Firefox
  • Safari (macOS)
  • Safari (iOS)
  • Chrome for Android
  • Not applicable

What else has been done to verify that this works as intended?

Why is this the best possible solution? Were any other approaches considered?

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Do we need any specific form for testing your changes? If so, please attach one.

What's changed

@changeset-bot
Copy link

changeset-bot bot commented Mar 2, 2026

🦋 Changeset detected

Latest commit: c65f3e2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@getodk/xforms-engine Patch
@getodk/web-forms Patch
@getodk/scenario Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines +421 to 450
type SetIntInputValueCase = {
[T in SetIntInputValueType]: BaseSetIntInputValueCase<T>;
}[SetIntInputValueType];

it.each<SetIntInputValueCase>([
{ inputType: 'bigint', inputValue: 89n, expectedValue: 89n },
{ inputType: 'number', inputValue: 10, expectedValue: 10n },
{ inputType: 'string', inputValue: '23', expectedValue: 23n },
{ inputType: 'null', inputValue: null, expectedValue: null },
{ inputType: 'string', inputValue: '10.1', expectedValue: 10n },
{ inputType: 'number', inputValue: 10.1, expectedValue: 10n },
])(
'$inputValue ($inputType), resulting in value $expectedValue',
({ inputValue, expectedValue }) => {
scenario.answer('/root/int-value', inputValue);
answer = getTypedInputNodeAnswer('/root/int-value', 'int');

expectTypeOf(answer.value).toEqualTypeOf<bigint | null>();
expectTypeOf(answer.value).toEqualTypeOf<bigint | null>();

if (expectedValue == null) {
expect(answer.value).toBeNull();
expect(answer.stringValue).toBe('');
} else {
expect(answer.value).toBeTypeOf('bigint');
expect(answer.value).toBe(expectedValue);
expect(answer.stringValue).toBe(`${expectedValue}`);
if (expectedValue == null) {
expect(answer.value).toBeNull();
expect(answer.stringValue).toBe('');
} else {
expect(answer.value).toBeTypeOf('bigint');
expect(answer.value).toBe(expectedValue);
expect(answer.stringValue).toBe(`${expectedValue}`);
}
}
});
);
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just reformatted this so because it was silly to have a describe per test.

scenario.answer('/stats/balance', '-5');
expect(scenario.answerOf('/stats/balance').getValue()).toBe('');
});
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find any existing tests for range which was weird, so wrote this very basic one. It didn't fit in bind-types because range is a style not a type.

@garethbowen garethbowen requested a review from latin-panda March 2, 2026 22:22
Copy link
Collaborator

@latin-panda latin-panda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! It’s great to have the codecs consistent now :)

I’ve been thinking about the UI/UX for invalid data entry and feel we still need Aly’s perspective. What do you think about opening a follow-up ticket so we can dive deeper into that later?

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.

Don't throw Errors when loading invalid values

2 participants