Angular Material - Required strings aren't validated



  • Angular 7 with jsonforms/core@2.3.0 / jsonforms/angular-material@2.3.0

  • Angular 9 with jsonforms/core@2.4.0 / jsonforms/angular-material@2.4.0

Given a very simple data object

  "name": "",
  "age": 12

And using the API to generate the default schema and uischema

// schema
  "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer" }},
  "additionalProperties": true,
  "required": [ "name", "age" ]

// uischema
  "type": "VerticalLayout",
  "elements": [
    { "type": "Control", "scope": "#/properties/name" },
    { "type": "Control", "scope": "#/properties/age" }

Expected behavior

The generated form will validate BOTH properties when they are not provided.

Actual behavior

Only non-string data types are validated.


NOTE: If I set minLength to 1 in the schema that validation does fire.

Any input on where I have gone wrong would be great. I can share the Angular 7 app - it was based on a clone of the make-it-happen-angular repository altered to get familiar with JSON forms and used to test different schema layouts…

[original thread by Thad Peiffer]

Hi @specantt(specantt) ,
you didn’t do anything wrong.
The problem is, that an empty string is a valid value for a string and thus the required validation of JsonSchema is fulfilled.
So if your requirement is that the string has a length of at least 1 you must explicitly state so, just as you did.

[Thad Peiffer]

Ahhh. Makes sense, though not what I had expected. I will adjust, thanks!