angular-schema-form icon indicating copy to clipboard operation
angular-schema-form copied to clipboard

Enums without type set, don't display even though valid

Open mark007 opened this issue 8 years ago • 5 comments

Enhancement

As a user/developer, when I try to display an enum field that doesn't have the "type" set

Expected behaviour

I expected the enum to display, even without the type set to something like "string"

Actual behaviour

It actually doesn't appear, and I don't see any error that the field is not understandable / not being displayed

json schema validators like ajv seem to not think the type is required on enums. Also on this doc https://spacetelescope.github.io/understanding-json-schema/reference/generic.html, it says "You can use enum even without a type, to accept values of different types..."

@json-schema-form/angular-schema-form-lead

mark007 avatar Apr 04 '17 12:04 mark007

@mark007 What would you expect to see displayed, I assume you are meaning without defining something in the form schema by using "*"?

Say for their example: "enum": ["red", "amber", "green", null, 42]?

Anthropic avatar Apr 04 '17 13:04 Anthropic

Hi Anthropic. Heres a gist example (I'm getting good at this ;) ) http://schemaform.io/examples/bootstrap-example.html#/bf745ed6e106ab3343bc3b9d291c4806

Would you have hoped the field to appear in this case, or is it by design that it doesn't show up in these cases.

Yes I always use "*" as the tool I'm working on, the schemas will be delivered into it, and we dont want to even know what the fields actually are or have to mention them anywhere in our codebase, so we are using "*", and want any schema they deliver to appear as a form basically.

mark007 avatar Apr 04 '17 14:04 mark007

Thanks @mark007, the problem is knowing what and how to display it, json-schema is not a spec with any form structure in mind at all, quite the opposite in fact, I am working with the people behind it to try and formalise some rules around that, but for now it really only considers data model and validation which makes things hard for frameworks generating a ui.

The reason I asked about "enum": ["red", "amber", "green", null, 42] is that without a type, I can't know what form element the user intends to display, maybe a drop down, maybe a text field, radios, an enum can contain any type, what if there are objects in it, it can get very tricky very quickly...

If you are only going to have string, numeric and null values, you can add in a type attribute coercion function with minimal effort, check out setting-up-schema-defaults which should work, but I haven't tried it so no promises, in fact if you try it and it doesn't work that is something I would definitely look at adding. In fact I could add it as an option to turn on and off I suppose, but you may have to use the workaround for now.

Anthropic avatar Apr 04 '17 22:04 Anthropic

Ah yes now I see, thanks for the explanation. I will try out the defaults at some point. My only concern in general is there many be understandably many of these cases where the form may perhaps not show a field and the user may receive no hint or error as to why the model of the data is not validating later against say an ajv validator. Thats the only place I could see a possible improvement, ie a general way to inform that the form couldn't be displayed to completely allow them to generate the required data.

I guess those validators would show the fields that were missing I guess the user could use that to tell them what the form wasn't able to help them generate I suppose.

Thanks for the explanation.

mark007 avatar Apr 05 '17 07:04 mark007

I agree it should probably be triggering a warning at least that there are fields not rendered, not sure about showing the end user that though, although a flag could conceivably allow that to be a developer choice.

Anthropic avatar Apr 05 '17 22:04 Anthropic