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

schemaForm.merge reports incorrect keys for array object properties #900

Closed donalmurtagh closed 7 years ago

donalmurtagh commented 7 years ago

Overview

In the latest version (1.0.0-alpha.5), the schemaForm.merge function reports incorrect keys for object properties stored in an array

Steps to Reproduce

  1. Open this Plunker demo
  2. Click the "Merge form and schema button" and look at the result
  3. In the result section, look at the keys reported for the child's name and age

Name

                "key": [
                  "",
                  0,
                  "peopleLivingWithYou",
                  "dependentChildren",
                  0
                ],

Age

                "key": [
                  "",
                  0,
                  "peopleLivingWithYou",
                  "dependentChildren",
                  0
                ],

Obviously these properties should not have the same key, and name and age should be last elements of the key array.

If you remove the section from the form, i.e. change the form definition to

    $scope.form = [{
        key: 'peopleLivingWithYou.dependentChildren',
        add: "Add Child",
        title: 'Dependent children details',
        validationMessage: 'Complete all required fields for at least one child'
      }];

The keys are correctly reported as

Name

            "key": [
              "peopleLivingWithYou",
              "dependentChildren",
              0,
              "name"
            ],

Age

            "key": [
              "peopleLivingWithYou",
              "dependentChildren",
              0,
              "age"
            ],

This problem does not exist in version 0.8.13.

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

Anthropic commented 7 years ago

Thanks @donalmurtagh I will turn this into a test case to ensure the scenario is supported in future changes as well.

Anthropic commented 7 years ago

@donalmurtagh this test is passing in the latest changes I merged, please re-open if there's anything still not working in relation to this :)

donalmurtagh commented 7 years ago

@Anthropic I've updated the Plunker demo to use the latest code and agree that this issue is now resolved. By the way, I don't have permission to re-open issues.