Angular CLI version 15.2.0. Node version 18.14.0
- Angular 15: DEMO
npm install ngx-json2form
NPM Package: https://www.npmjs.com/package/ngx-json2form
import { NgxJson2formModule } from 'ngx-json2form';
-
<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>
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;
})
}
{
"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.mask"
- doc
min?: number;
max?: number;
required?: boolean;
requiredTrue?: boolean;
email?: boolean;
minLength?: number;
maxLength?: number;
pattern?: string;
nullValidator?: boolean;
`
min?: string;
max?: string;
required?: string;
requiredTrue?: string;
email?: string;
minLength?: string;
maxLength?: string;
pattern?: string;
nullValidator?: string;
`
Run command npm run generate:readme:badges
Form are built using material-angular, so just adjust theme. Theme Angular Material
in the future it will be extended for custom validators
in the future it will be developed
in the future it will be developed
in future it will be developed
in future it will be developed
Im open for contribution, just write to me! :)
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.