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

ERROR Error: schema is invalid: data/properties/form should be object,boolean #29

Closed
1 of 5 tasks
koczkadavid opened this issue Oct 17, 2018 · 3 comments
Closed
1 of 5 tasks

Comments

@koczkadavid
Copy link

Describe the bug
which template:

  • MaterialDesignFrameworkModule — Material Design
  • Bootstrap3FrameworkModule — Bootstrap 3
  • Bootstrap4FrameworkModule — Bootstrap 4
  • NoFrameworkModule — plain HTML
  • Other (please specify below)

A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. install package with npm
  2. fix issues related to missing packages (flex-layout and material)
  3. imported needed modules
  4. trying to use schema from example
  5. ERROR Error: schema is invalid: data/properties/form should be object,boolean

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
image

Desktop (please complete the following information):

  • OS: Ubuntu 18.04Lts on Gnome 3.28
  • Browser: chrome
  • Version: latest

Log output covering before error and any error statements

ERROR Error: schema is invalid: data/properties/form should be object,boolean
    at Ajv.validateSchema (ajv.js:183)
    at Ajv._addSchema (ajv.js:312)
    at Ajv.compile (ajv.js:112)
    at JsonSchemaFormService.push../node_modules/angular6-json-schema-form/fesm5/angular6-json-schema-form.js.JsonSchemaFormService.compileAjvSchema (angular6-json-schema-form.js:6099)
    at JsonSchemaFormComponent.push../node_modules/angular6-json-schema-form/fesm5/angular6-json-schema-form.js.JsonSchemaFormComponent.initializeSchema (angular6-json-schema-form.js:8602)
    at JsonSchemaFormComponent.push../node_modules/angular6-json-schema-form/fesm5/angular6-json-schema-form.js.JsonSchemaFormComponent.initializeForm (angular6-json-schema-form.js:8435)
    at JsonSchemaFormComponent.push../node_modules/angular6-json-schema-form/fesm5/angular6-json-schema-form.js.JsonSchemaFormComponent.updateForm (angular6-json-schema-form.js:8336)
    at JsonSchemaFormComponent.push../node_modules/angular6-json-schema-form/fesm5/angular6-json-schema-form.js.JsonSchemaFormComponent.ngOnChanges (angular6-json-schema-form.js:8312)
    at checkAndUpdateDirectiveInline (core.js:9246)
    at checkAndUpdateNodeInline (core.js:10514)

Detailed Description

Context

Possible Implementation

@hamzahamidi
Copy link
Owner

Thank you for using the library. Can you please post the json schema you used to reproduce the issue?

@koczkadavid
Copy link
Author

It was the Hack: Conditions one from the examle.
Also, can you please provide some info on how to work with the conditions? I've tried to pass a boolean from any source, in string or standard bool format, but none of them worked, apart from the boolean toggles from the schema itself.

https://hamidihamza.com/Angular6-json-schema-form/?set=asf&example=asf-hack-conditional-required&framework=material-design&language=en

@hamzahamidi
Copy link
Owner

hamzahamidi commented Oct 17, 2018

{
  "schema": {
    "type": "object",
    "properties": {
      "commentary": {
        "title": "commentary",
        "type": "string",
      },
      "depCommentary": {
        "title": "dependant commentary",
        "type": "integer"
      },
    "notDisplayedcommentary": {
        "title": "this commentary will not be displayed no matter what",
        "type": "string",
      },
    },
    "required": [
    ]
  },
  "form": [
    {
      "type": "help",
      "helpvalue": "<p>This is a work around to use conditions in <b>angular6-json-schema-form</b>. </br> Schema Form does not support oneOf (yet), but you can do a workaround and simulate certain scenarios with 'condition' and 'required'  (and/or 'readonly') in the form.</p>"
    },
    "commentary",
    {
      "key": "depCommentary",
      "condition": "model.commentary",
      "required": true
    },
    {
      "key": "depCommentary",
      "condition": "!model.commentary"
    },
    {
      "type": "submit",
      "style": "btn-info",
      "title": "OK"
    }
  ]
}

This is only a workaround & doesn't abide by the rules of the Json schema drafts. You still need to use the object "form", where you need to specify the content of you HTML form.

In the example above you can see I added the key "commentary". This means that the field "commentary" will be displayed by default.

"notDisplayedcommentary" will not be displayed because it doesn't exist in the "form" object.

As for "depCommentary", it will display but depending on the condition if "commentary" is not undefined.

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

No branches or pull requests

2 participants