Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
atavakoli opened this issue Dec 24, 2017 · 0 comments
Open

Comments

@atavakoli
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants