12.2.1 • Published 2 years ago

@dr-angular/form-material v12.2.1

Weekly downloads
141
License
-
Repository
-
Last release
2 years 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

2 years ago

0.0.82

2 years ago

13.3.1

2 years ago

13.3.0

2 years ago

12.2.1

2 years ago

12.2.0

2 years ago

0.0.80

3 years ago

0.0.79

3 years ago

0.0.73

3 years ago

0.0.74

3 years ago

0.0.75

3 years ago

0.0.76

3 years ago

0.0.77

3 years ago

0.0.78

3 years ago

0.0.72

3 years ago

0.0.70

3 years ago

0.0.71

3 years ago

0.0.65

3 years ago

0.0.66

3 years ago

0.0.67

3 years ago

0.0.68

3 years ago

0.0.69

3 years ago

0.0.63

3 years ago

0.0.64

3 years ago

0.0.62

3 years ago

0.0.60

3 years ago

0.0.61

3 years ago

0.0.56

3 years ago

0.0.57

3 years ago

0.0.58

3 years ago

0.0.54

4 years ago

0.0.55

4 years ago

0.0.53

4 years ago

0.0.51

4 years ago

0.0.52

4 years ago

0.0.50

4 years ago

0.0.49

4 years ago

0.0.48

4 years ago

0.0.47

4 years ago

0.0.44

4 years ago

0.0.45

4 years ago

0.0.46

4 years ago

0.0.43

4 years ago

0.0.42

4 years ago

0.0.41

4 years ago

0.0.40

4 years ago

0.0.39

4 years ago

0.0.38

4 years ago

0.0.37

4 years ago

0.0.36

4 years ago

0.0.34

4 years ago

0.0.35

4 years ago

0.0.33

4 years ago

0.0.31

4 years ago

0.0.32

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.25

5 years ago

0.0.26

5 years ago

0.0.27

5 years ago

0.0.28

5 years ago

0.0.23

5 years ago

0.0.24

5 years ago

0.0.20

5 years ago

0.0.21

5 years ago

0.0.22

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.1

5 years ago