Skip to content

Commit

Permalink
FIX Don't split ID into separate digits (#335)
Browse files Browse the repository at this point in the history
GuySartorelli authored Sep 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent dcc43fa commit 2ca8c0a
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions client/src/components/LinkField/LinkField.js
Original file line number Diff line number Diff line change
@@ -135,12 +135,10 @@ const LinkField = ({
})
);

// The value for a has_one LinkField will start off as a numeric 0
// If a parent object containing a child LinkField without a value is submitted,
// using FormSchema, then the FormSchema response may contain a string '0' instead
// Ensure that a numeric 0 is used
if (value === '0') {
value = 0;
// Sometimes, the value will be given as a numeric string.
// Ensure that an actual number is used
if (typeof value === 'string') {
value = Number(value);
}

// Ensure we have a valid array
16 changes: 16 additions & 0 deletions client/src/components/LinkField/tests/LinkField-test.js
Original file line number Diff line number Diff line change
@@ -94,6 +94,22 @@ test('LinkField can handle a string "0" value', async () => {
expect(container.querySelectorAll('.link-picker')).toHaveLength(1);
});

test('LinkField can handle a multi-digit string value', async () => {
const { container } = render(<LinkField {...makeProps({
value: '123'
})}
/>);

await doResolve({ json: () => ({
123: {
title: 'Page title',
typeKey: 'sitetree',
},
}) });
await screen.findByText('Page title');
expect(container.querySelectorAll('.link-picker__button')).toHaveLength(1);
});

test('LinkField will render disabled state if disabled is true', async () => {
const { container } = render(<LinkField {...makeProps({
ownerID: 1,

0 comments on commit 2ca8c0a

Please sign in to comment.