dschnelldavis / angular2-json-schema-form

Angular 2 JSON Schema Form builder
MIT License
285 stars 177 forks source link

2 forms cannot exist at same time #120

Open stalsma opened 6 years ago

stalsma commented 6 years ago

I found this by accident; no real use case. But it is unexpected. The second form simply overwrites the first one. Is the service somehow stateful, and the data from the second instance gets stored in the service, overwriting the configuration of the first instance?

Here's a simple component to reproduce:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'simple-component',
  template: `
    <json-schema-form [data]="jsonFormObject1"
                      [options]="jsonFormOptions"></json-schema-form>

    <json-schema-form [data]="jsonFormObject2"
                      [options]="jsonFormOptions"></json-schema-form>

  `
})
export class SimpleComponent implements OnInit {

  jsonFormObject1: object = {
    data: {
      username: 'JoeSmith',
      password: '1234'
    }
  };

  jsonFormObject2: object = {
    first_name: 'Jane',
    last_name: 'Doe',
  };

  constructor() { }

  ngOnInit() {
  }

  jsonFormOptions: any = {
    addSubmit: true, // Add a submit button if layout does not have one
    loadExternalAssets: true, // Load external css and JavaScript for frameworks
    formDefaults: { feedback: true }, // Show inline feedback icons
    debug: false,
    returnEmptyFields: false,
  };
}
qid14 commented 6 years ago

I met the same issue, weird.

qid14 commented 6 years ago

I found the old version 0.5.0-alpha.2 is OK, above versions fail. While the layout is different in this version.

dschnelldavis commented 6 years ago

That's odd.

OK, since it was working before, I've changed this from "enhancement" back to "bug."

I don't know what's causing it, but I'll try to figure it out.

ofirpar commented 6 years ago

Maybe add the providers from module to the json-schema Component This way, each service will have its own instance for each json-schema component and manage data for each instance individually.

ChrisButtermelon commented 6 years ago

@dschnelldavis any update on a fix for this bug? i am facing the same issue. :)