json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

version(0.8.14) regression in conditional array validation #986

Open rthaut opened 6 years ago

rthaut commented 6 years ago

This appears to be a new bug introduced in version 0.8.14.

Basically, if you have an array property in your schema, and that property is conditional, the form is not being validated correctly.

Here is a reduced example showing it working with version 0.8.13.

Here is the exact same example NOT working with version 0.8.14.

In both examples, if you check the "Show Array Elements" checkbox, the array section appears. If you provide at least a value for Field 1 and submit, the form validates for 0.8.13, but not for 0.8.14.

In 0.8.14, the form has the following $error:

"$error": {
  "schemaForm": [
    {
      "$viewValue": [
        {
          "Field1": "My Test Value for Field1"
        }
      ],
      "$modelValue": [
        {
          "Field1": "My Test Value for Field1"
        }
      ],
      "$validators": {},
      "$asyncValidators": {},
      "$parsers": [
        null
      ],
      "$formatters": [
        null
      ],
      "$viewChangeListeners": [],
      "$untouched": true,
      "$touched": false,
      "$pristine": false,
      "$dirty": true,
      "$valid": false,
      "$invalid": true,
      "$error": {
        "schemaForm": true
      },
      "$name": "",
      "$options": {}
    }
  ]
}

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

Anthropic commented 6 years ago

@rthaut wow, that's an interesting case. No doubt plenty of users have it. Thanks for the demos, it does seem related to the condition as removing the condition it works in both, I suspect it was related to some fo the array changes that went into the branch mid last year.

Anthropic commented 6 years ago

@rthaut can you test again with the bootstrap decorator from 0.8.13 with ASF 0.8.14? I think it just included a version of the decorator too new for the code in ASF.

rthaut commented 6 years ago

@Anthropic Using the Bootstrap Decorator from 0.8.13 with ASF 0.8.14 does indeed work correctly, at least for this scenario. Here's a demo: https://codepen.io/rthaut/full/qMWpaV/