jsonforms icon indicating copy to clipboard operation
jsonforms copied to clipboard

Should formatIs ranker support null types?

Open alastair-todd opened this issue 3 years ago • 3 comments

Describe the bug

export const formatIs = (expectedFormat: string): Tester =>
  schemaMatches(
    schema =>
      !isEmpty(schema) &&
      schema.format === expectedFormat &&
      schema.type === 'string'
  );

Expected behavior

Should support nulls

type: ['string', 'null']

Steps to reproduce the issue

N/A

Screenshots

No response

In which browser are you experiencing the issue?

N/A

Framework

Core

RendererSet

No response

Additional context

No response

alastair-todd avatar Sep 13 '21 11:09 alastair-todd

Hi @alastair-todd thanks for the report. If I read the spec correctly we should probably not hard code a check against null but rather check whether string is included in the type array.

The only problem I see here is for users who are already using formatIs, rely on the type always being a string and then suddenly their custom renderer is also invoked on other types.

sdirix avatar Sep 13 '21 12:09 sdirix

In the mean time you can always write your own version of formatIs which works "properly"

sdirix avatar Sep 13 '21 12:09 sdirix

Well yeah I've gone and created my own testers.

const formatIs = (expectedFormat: string): Tester => 
  schemaMatches((schema) => !isEmpty(schema) && schema.format === expectedFormat);

Its the same for oneOf with a null value e.g.

[
   {
      "title":" ",
      "type":"null"
   },
   {
      "title":"Permanent",
      "const":"Permanent"
   },
   {
      "title":"Temporary",
      "const":"Temporary"
   },
   {
      "title":"Casual",
      "const":"Casual"
   }
]
const isOneOfEnumControl = and(
  uiTypeIs('Control'),
  schemaMatches(schema =>
    schema.hasOwnProperty('oneOf')
  )
);

(removed the in-built version's forcing all options to be const)

alastair-todd avatar Sep 13 '21 12:09 alastair-todd

This was fixed with https://github.com/eclipsesource/jsonforms/pull/1925

sdirix avatar Nov 25 '22 14:11 sdirix