formly-js / angular-formly

JavaScript powered forms for AngularJS
http://docs.angular-formly.com
MIT License
2.22k stars 405 forks source link

formly-field-directive-validation-failed #606

Closed quintenvk closed 8 years ago

quintenvk commented 8 years ago

I'm currently importing the following JSON as fields:

[{
    "key": "username",
    "type": "input",
    "templateOptions": {
        "label": "Gebruikersnaam",
        "required": true
    }
}, {
    "key": "password",
    "type": "input",
    "templateOptions": {
        "type": "password",
        "label": "Wachtwoord",
        "required": true
    }
}]

But yet, I get the error stated in the title. This is what I get back from the API:

The API calls for:
{
  "__apiCheckData": {
    "strict": true,
    "optional": false,
    "type": "shape"
  },
  "shape": {
    "key": {
      "__apiCheckData": {
        "optional": true,
        "type": "oneOfType"
      },
      "oneOfType": [
        "String",
        "Number"
      ]
    },
    "originalModel": {
      "__apiCheckData": {
        "optional": true,
        "type": "oneOfType"
      },
      "oneOfType": [
        "String",
        "Object"
      ]
    },
    "extras": {
      "__apiCheckData": {
        "strict": true,
        "optional": true,
        "type": "shape"
      },
      "shape": {}
    },
    "data": "Object (optional)",
    "templateOptions": "Object (optional)",
    "validation": {
      "__apiCheckData": {
        "strict": false,
        "optional": true,
        "type": "shape"
      },
      "shape": {}
    },
    "value": "Function (optional)",
    "runExpressions": "Function (optional)",
    "resetModel": "Function (optional)",
    "updateInitialValue": "Function (optional)"
  }
}

As far as I can see, the data does fit the requirements. If I need to post my types/wrappers as well, let me know.

quintenvk commented 8 years ago

Issue can be closed. The error was as follows:

I had a JSON file that had an array of objects in it (to configure my inputs). That json file was imported by webpack as follows: import * as fields from './form-fields.json'; I then assigned the fields as $scope.fields = fields;

This assigned a fields object, so the fix was $scope.fields = fields.default; in order to access the array as intended.