1.0.8 • Published 5 years ago

ngx-antd-json-schema-form v1.0.8

Weekly downloads
17
License
MIT
Repository
github
Last release
5 years ago

ngx-antd-json-schema-form

JSON schema form with ant-design and prsimjs

Build Status npm version

This plugin uses ng-zorro-antd and prismjs

Demo: https://bhavinpatel04.github.io/ngx-antd-json-schema-form/

Features

Emits the new updated schema when the form value changes

Installation

Install the plugin from npm:

npm install ngx-antd-json-schema-form --save

import NgxAntdJsonSchemaFormModule in your module:

...
import { FormsModule } from '@angular/forms';
import { NgxAntdJsonSchemaFormModule } from 'ngx-antd-json-schema-form';
import { AppComponent } from "./app.component";

@NgModule({
    imports:      [... , FormsModule, NgxAntdJsonSchemaFormModule],
    declarations: [AppComponent],
    bootstrap:    [AppComponent]
})
export class AppModule {}

Add Styles in angular.json:

  ...
  "assets": [...],
  "styles": [
    "node_modules/ng-zorro-antd/ng-zorro-antd.min.css",
    "node_modules/prismjs/themes/prism.css",
    "src/styles.scss"
  ],
  ...

Usage example

The component using this library should have encapsulation: ViewEncapsulation.None

Html:

<ngx-antd-json-schema-form [(schema)]="schema" [settings]="settings" (submit)="submit($event)">
</ngx-antd-json-schema-form>

Typescript:

schema: [
  {
    key: "input",
    label: "input",
    type: "input",
    required: true,
    value: ""
  },
  {
    key: "input-hidden",
    label: "input-hidden",
    type: "input",
    required: true,
    hidden: true,
    value: "blah-blah"
  },
  {
    key: "checkbox",
    label: "checkbox",
    type: "checkbox",
    required: true,
    value: true
  },
  {
    key: "radio",
    label: "radio",
    type: "radio",
    required: true,
    value: "yes",
    options: [
      {
        label: "Yes",
        value: "yes"
      },
      {
        label: "No",
        value: "No"
      }
    ] as FormOption[]
  },
  {
    key: "radio-button",
    label: "radio-button",
    type: "radio-button",
    required: false,
    value: false,
    options: [
      {
        label: "Yes",
        value: true
      },
      {
        label: "No",
        value: false
      }
    ] as FormOption[]
  },
  {
    key: "select",
    label: "select",
    type: "select",
    options: [
      {
        label: "Option 1",
        value: "1"
      },
      {
        label: "Option 2",
        value: "2"
      }
    ] as FormOption[],
    value: "1"
  },
  {
    key: "textarea",
    label: "textarea",
    type: "textarea",
    required: true,
    value: ""
  },
  {
    key: "prism",
    label: "prism",
    type: "prism",
    language: "typescript",
    required: true,
    value:
      '[\n  {\n  "name": "user_id",\n  "isPii": false,\n  },\n  {\n  "name": "user_name",\n  "isPii": true,\n }\n]',
    disabled: true,
    fieldClass: "prism-class"
  },
  {
    key: "icon",
    label: "icon",
    type: "icon",
    required: false,
    value: "any value, does not matter",
    disabled: false,
    icon: {
      type: "check-circle",
      theme: "fill",
      class: "form-icon-class"
    } as FormIcon
  }
] as FormItem[];
settings: FormSettings = {
  fieldClass: "field-class"
};

Options

OptionTypeDescription
schemaFormItem[]json schema
settingsFormSettingssettings

Item Options

OptionTypeDescription
keystringkey
labelstringlabel
typestringtype
placeholderstringplaceholder
optionsFormOption[]Array of options
disabledbooleandisabled
readonlybooleanreadonly
valuestringvalue
requiredbooleanrequired
languagestringlanguage
nzGutternumbernzGutter
itemClassstringitemClass
nzSpanLabelnumbernzSpanLabel
labelClassstringlabelClass
nzSpanControlnumbernzSpanControl
fieldClassstringfieldClass

Settings

SettingTypeDefaultDescription
nzGutternumber8nzGutter attr of ng-zorro-antd
itemClassstring''class for the item
nzSpanLabelnumber8nzSpan attr of ng-zorro-antd for label
labelClassstring''class for the item-label
nzSpanControlnumber16nzSpan attr of ng-zorro-antd for control-field
fieldClassstring''class for the control-field

License

MIT

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago