Skip to content

Array with nulls/empty strings accepted, contradicting schema in items #945

Open
@atavakoli

Description

@atavakoli

As a developer, I expect to be able to define a schema for an array of non-empty strings, for which form validation rejects an array containing one or more empty strings.

Expected behaviour

Using the following schema:

{
  "type": "object",
  "properties": {
    "listOfNonEmptyStrings": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      }
    }
  },
  "required": [
    "listOfNonEmptyStrings"
  ]
}

and the following form config:

[
  "*",
  {
    "type": "submit",
    "title": "OK"
  }
]

... in the generated form, leave one or more of the entries empty. I expect the form to be rendered as invalid.

Actual behaviour

Using the schema above accepts an array containing empty strings or null entries and renders the form as valid. Trying to use pattern instead of minLength (e.g. "pattern": "^.+$") has the same result. TV4 itself rejects the model.

I tried setting minLength of 2 instead of 1, and this rejects arrays containing single-character strings, but still accepts arrays with empty strings & null entries.

Gist/Plunker/Demo

Demo plunker

Empty string issue:

  1. Click Submit
  2. First alert says "angular-schema-form says form is valid", despite the array consisting of a single empty string.
  3. Second alert says "TV4 says form is not valid: String is too short (0 chars), minimum 1", which is correct.

Null entry issue:

  1. Delete the existing entry
  2. Add a new entry (and don't edit it)
  3. Click Submit
  4. First alert says "angular-schema-form says form is valid", despite the array consisting of a single null entry.
  5. Second alert says "TV4 says form is not valid: Invalid type: undefined (expected string)", which is correct.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions