Skip to main content

Usage

After installing the package and registering NvsDynamicFormModule (see Installation), you can render forms with the nvs-dynamic-form component.

nvs-dynamic-form inputs/outputs

NameTypeKindDescription
fromClassstringInputCSS class name for the generated form.
validatorOrOptsValidatorFn | ValidatorFn[] | AbstractControlOptionsInputExtra validators/options to apply to the underlying FormGroup.
submitButtonVisiblebooleanInputControls visibility of the submit button.
submitButtonLabelstringInputSubmit button label.
submitButtonIsFullWidthbooleanInputMakes the submit button full width.
submitButtonPosition'left' | 'right' | 'center'InputSubmit button alignment.
fieldsany[]InputThe field definitions (instances of your field model classes).
onSubmitEventEmitter<{ values: any; valid: boolean }>OutputFired when the form is submitted.

Simple example

app.component.ts
import { Component } from '@angular/core';
import { Validators } from '@angular/forms';

import { NvsDynamicFormModule, TextboxField } from '@nvs-dynamic-form/ng-core';

@Component({
selector: 'app-root',
standalone: true,
templateUrl: './app.component.html',
styleUrl: './app.component.scss',
imports: [NvsDynamicFormModule],
})
export class AppComponent {
fields = [
new TextboxField({
label: 'First Name',
key: 'firstName',
placeholder: 'test',
validators: [Validators.required],
screenSize: {
desktop: 6,
mobile: 12,
},
}),
new TextboxField({
label: 'Last Name',
key: 'lastName',
screenSize: {
desktop: 6,
mobile: 12,
},
}),
new TextboxField({
label: 'E-mail Address',
key: 'emailAddress',
screenSize: 12,
}),
];

onSubmit({ values, valid }: { values: any; valid: boolean }) {
if (valid) {
alert(JSON.stringify(values));
}
}
}
app.component.html
<nvs-dynamic-form [fields]="fields" (onSubmit)="onSubmit($event)"></nvs-dynamic-form>