12.2.1 • Published 5 months ago

@dr-angular/form-material v12.2.1

Weekly downloads
141
License
-
Repository
-
Last release
5 months ago

A very useful tool for view dynamic forms using angular material. It just needs a json as input.

Install the library and import the "FormMaterialModule" module

// ...

import { FormMaterialModule } from '@dr-angular/form-material';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    FormMaterialModule
  ]
})
export class AppModule { }

Construct the jsonHero object using the IDynamicForm interface:

@Input() jsonForm: IDynamicForm;
@Output() formSubmit: EventEmitter<any>;

formSubmitted: any = {};

// ...

jsonHero: IDynamicForm = {
  name: 'form_1',
  title: 'My example form',
  buttonResetName: 'Reset the form',
  buttonSubmitName: 'Save the form',
  buttonNextName: 'Next page',
  buttonPrevName: 'Prev page',
  buttonNextAlwaysEnabled: false,
  pages: [
    {
      name: 'page_1',
      title: 'Page 1',
      sections: [
        {
          name: 'section_chk',
          title: 'Prova',
          rows: [
            {
              cells: [
                {
                  type: 'CHECKBOX',
                  controlName: 'hide_section',
                  label: 'Hide section',
                }
              ]
            }
          ]
        },
        {
          name: 'hidden_if',
          title: 'Section to hide',
          hidden: 'hide_section === true',
          rows: [
            {
              cells: [
                {
                  type: 'TEXT',
                  controlName: 'text_required',
                  label: 'Text 1',
                  validators: [
                    {
                      type: 'REQUIRED'
                    }
                  ]
                }
              ]
            }
          ],
        }
      ]
    },
    {
      name: 'page_2',
      title: 'Page 2',
      sections: [
        {
          name: 'section_1',
          rows: [
            {
              cells: [
                {
                  type: 'CHECKBOX',
                  controlName: 'ctrlCheckbox',
                  label: 'Show message bo',
                  defaultValue: true
                },
                {
                  type: 'TEXTAREA',
                  cellSize: 5,
                  controlName: 'ctrlMessage',
                  label: 'Message Box',
                  hidden: [
                    'ctrlCheckbox === false'
                  ],
                  validators: [
                    {
                      type: 'REQUIRED'
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
};

An example of how to use the component

<div *ngIf="jsonHero">
    <dr-form-material [jsonForm]="jsonHero" (formSubmit)="formSubmitted=$event">
    </dr-form-material>
</div>

{{formSubmitted | json}}

To build the form consult the pack @dr-angular/form-material-builder.

npm i @dr-angular/form-material-builder
0.0.81

9 months ago

0.0.82

7 months ago

13.3.1

5 months ago

13.3.0

5 months ago

12.2.1

5 months ago

12.2.0

5 months ago

0.0.80

1 year ago

0.0.79

1 year ago

0.0.73

2 years ago

0.0.74

2 years ago

0.0.75

2 years ago

0.0.76

2 years ago

0.0.77

2 years ago

0.0.78

1 year ago

0.0.72

2 years ago

0.0.70

2 years ago

0.0.71

2 years ago

0.0.65

2 years ago

0.0.66

2 years ago

0.0.67

2 years ago

0.0.68

2 years ago

0.0.69

2 years ago

0.0.63

2 years ago

0.0.64

2 years ago

0.0.62

2 years ago

0.0.60

2 years ago

0.0.61

2 years ago

0.0.56

2 years ago

0.0.57

2 years ago

0.0.58

2 years ago

0.0.54

3 years ago

0.0.55

3 years ago

0.0.53

3 years ago

0.0.51

3 years ago

0.0.52

3 years ago

0.0.50

3 years ago

0.0.49

3 years ago

0.0.48

3 years ago

0.0.47

3 years ago

0.0.44

3 years ago

0.0.45

3 years ago

0.0.46

3 years ago

0.0.43

3 years ago

0.0.42

3 years ago

0.0.41

3 years ago

0.0.40

3 years ago

0.0.39

3 years ago

0.0.38

3 years ago

0.0.37

3 years ago

0.0.36

3 years ago

0.0.34

3 years ago

0.0.35

3 years ago

0.0.33

3 years ago

0.0.31

3 years ago

0.0.32

3 years ago

0.0.30

3 years ago

0.0.29

3 years ago

0.0.25

3 years ago

0.0.26

3 years ago

0.0.27

3 years ago

0.0.28

3 years ago

0.0.23

3 years ago

0.0.24

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.22

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.1

3 years ago