adampenn / Angular7-json-schema-form

Angular v7 for Angular2-json-schema-form
MIT License
5 stars 7 forks source link

How can I fill the form automatically and refresh? #14

Closed levyitay closed 4 years ago

levyitay commented 4 years ago

I have an empty form and I want to fill it with data (coming from a server) the [(data)] object doesn't work and the form doesn't refresh which template:

A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior: HTML:

<json-schema-form class="json-schema-form"
  loadExternalAssets="true"
  [schema]="schema"
  [form]="jsonFormObject"
  [(data)] = "selectedIntentData"
  [layout]="layoutOptions"
  [debug]="true"
  framework="material-design"
  (onSubmit)="onSubmit($event)">
</json-schema-form>

TS:

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

@Component({
  selector: 'intent-form',
  templateUrl: './intent-form.component.html',
  styleUrls: ['./intent-form.component.scss']
})

export class IntentFormComponent implements OnInit{

  constructor() { }
  schema: object = {

    "intent_name": {
      "type": "string",
      "required": true,
      "unique": true
    },
    "intent_id": {
      "type": "string",
      "required": true,
      "unique": true
    },
    "query": {
      "type": "string",
      "required": true
    },
    "params_names": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "param_name": {
            "type": "string",
          },
          "mandatory": {
            "type": "boolean",
          },
          "should_use_like": {
            "type": "boolean",
            "default": false
          },
          "query": {
            "type": "string",
          },
          "query_place_holder": {
            "type": "string",
          }
        },
        "required": ["param_name", "query", "query_place_holder"]
      }
    },
    "requieres_follow_up": {
      "type": "boolean"
    },
    "follow_up_question": {
      "type": "string"
    },
    "in_context_params": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "in_context_name": {
      "type": "string"
    },
    "intent_msg_response": {
      "type": "string",
      "required": true

    },
    "user": {
      "type": "string",
      "required": true

    },
    "cluster": {
      "type": "string",
      "required": true

    },
    "postProcess": {
      "type": "string"
    },
    "preProcess": {
      "type": "string"
    }
  };
  data:object;
  layoutOptions:any = [
    "*",

    { type: 'submit', title: 'Save' }

  ]
  jsonFormObject:any= {};
  selectedIntentData:object  = {};

  ngOnInit() {
  }
  onSubmit(event) {
    console.log('submit')

  }
  fillForm(dataObj){
    this.selectedIntentData = dataObj;

  }

  updateData(dataObj){
    this.data = dataObj;
  }

}
  1. ...

Expected behavior Form should update when selectedIntentData is changed.

levyitay commented 4 years ago

managed to fix it myself