Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remoteoss/json-schema-form",
"version": "0.7.3-beta.0",
"version": "0.7.2-beta.0",
"description": "Headless UI form powered by JSON Schemas",
"author": "Remote.com <[email protected]> (https://remote.com/)",
"license": "MIT",
Expand Down
4 changes: 4 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const dynamicInternalJsfAttrs = [
'calculateConditionalProperties', // driven from conditionals
'calculateCustomValidationProperties', // To be deprecated in favor of json-logic
'scopedJsonSchema', // The respective JSON Schema

// HOTFIX/TODO Internal customizations, check test conditions.test.js for more info.
'Component',
'calculateDynamicProperties',
];
const dynamicInternalJsfAttrsObj = Object.fromEntries(
dynamicInternalJsfAttrs.map((k) => [k, true])
Expand Down
58 changes: 58 additions & 0 deletions src/tests/conditions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,62 @@ describe('Conditional attributes updated', () => {
],
});
});

it('Keeps custom attribute Component (fieldAttrsFromJsf) (hotfix temporary)', () => {
// This is necessary as hotfix because we (Remote) use it internally.
// Not cool, we'll need a better solution asap.
const { fields, handleValidation } = createHeadlessForm(
{
properties: {
is_full_time: { type: 'string', oneOf: [{ const: 'yes' }, { const: 'no' }] },
salary_period: {
type: 'string',
title: 'Salary period',
oneOf: [
{ title: 'Weekly', const: 'weekly' },
{ title: 'Monthly', const: 'monthly' },
],
},
},
allOf: [
{
if: {
properties: { is_full_time: { const: 'yes' } },
required: ['is_full_time'],
},
then: {
properties: {
salary_period: {
description: 'We recommend montlhy.',
},
},
},
},
],
},
{
strictInputType: false,
customProperties: {
salary_period: {
Component: '<A React Component>',
calculateDynamicProperties: () => true,
},
},
}
);

// It's there by default
expect(fields[1].Component).toBe('<A React Component>');
expect(fields[1].calculateDynamicProperties).toEqual(expect.any(Function));

// Given "Yes", it stays there too.
handleValidation({ is_full_time: 'yes' });
expect(fields[1].Component).toBe('<A React Component>');
expect(fields[1].calculateDynamicProperties).toEqual(expect.any(Function));

// Given "No", it stays there too.
handleValidation({ is_full_time: 'no' });
expect(fields[1].Component).toBe('<A React Component>');
expect(fields[1].calculateDynamicProperties).toEqual(expect.any(Function));
});
});