0.0.11 • Published 1 year ago

ngx-json2form v0.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago


NgxJson2form

Angular CLI version 15.2.0. Node version 18.14.0

Live demo:

Install:

npm install ngx-json2form

NPM Package: https://www.npmjs.com/package/ngx-json2form

Example usage:

  1. import { NgxJson2formModule } from 'ngx-json2form';
  2.     <div class="container">
            <json2form #json2formElement *ngIf="json && formGroup" [JSON]="json" [(formGroup)]="formGroup"
                formId="example-form" (ngSubmit)="saveForm()"></json2form>
            <button mat-raised-button form="example-form" type="submit">SAVE</button>
        </div>
  3.  public formGroup = new FormGroup({});
     public json: JsonFormResponse | null = null;
    
     constructor(private httpClient: HttpClient) {
    
     }
     ngOnInit(): void {
       this.httpClient.get<JsonFormResponse>('../assets/forms/example.json').pipe(take(1)).subscribe(json => {
         this.json = json;
       })
     }

Documentation

API

[JSON]="your_json" - value correct json structure string or object. Only 1 level of nesting. @Input

([formGroup])="your_empty_form_group" - two way bindings formGroup @Input/@Output

(ngSubmit)="your_method()" - emit void event on submit @Output

JSON STRUCTURE

Base structure is

{
    "controls": [
        {
            "sortOrder": 1,
            "name": "favColor",
            "label": "Favourite color",
            "value": "blue",
            "type": "select",
            "validators": {
                "type": {
                    "required": true
                },
                "message": {
                    "required": "custom error message for required"
                }
            }
        },
        {
            "sortOrder":2,
            "name": "zipcode",
            "label": "zip code",
            "value":"",
            "type":"text",
            "validators":{
                "type":{
                    "required": true,
                    "minLength":5,
                    "maxLength":5
                }
            },
            "mask":"[00-000]"
        }
    ],
    "dictionaries": {
        "favColor": [
            {
                "label": "red",
                "value": "red"
            },
            {
                "label": "blue",
                "value": "blue"
            }]
    }
}

"controls" - list of controls which will be rendered

"controls.sortOrder" - order of element

"controls.name" - name for angular form control

"controls.label" - label for angular form control

"controls.value" - value for angular form control

"controls.mask" - doc

"controls.type" - one of "text" | "checkbox" | "number" | "select"

"controls.validators.type" - (optional) anys of default validators and argument`

min?: number;
max?: number;
required?: boolean;
requiredTrue?: boolean;
email?: boolean;
minLength?: number;
maxLength?: number;
pattern?: string;
nullValidator?: boolean;

`

"controls.validators.message" - any of default validators and custtom error message`

min?: string;
max?: string;
required?: string;
requiredTrue?: string;
email?: string;
minLength?: string;
maxLength?: string;
pattern?: string;
nullValidator?: string;

`

"dictionaries" - object, where keys are equal to angular form control name ("controls.name")

"dictionaries["controls.name"] - list of elements for select control

"dictionaries["controls.name"].label - label for element item

"dictionaries["controls.name"].value - value for element item

README.md

Genereting badges in README

Run command npm run generate:readme:badges

Styles

Form are built using material-angular, so just adjust theme. Theme Angular Material

TODO

validators

in the future it will be extended for custom validators

suffix

in the future it will be developed

preffix

in the future it will be developed

disabled

in future it will be developed

file input

in future it will be developed

Contribution

Im open for contribution, just write to me! :)

Legal

Copyright 2023 Szymon Wasiak

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago