0.9.72 • Published 6 months ago

ionic-global-form v0.9.72

Weekly downloads
-
License
-
Repository
-
Last release
6 months ago

Converts JSON objects into Angular reactive forms and returns FormGroup.

Ionic Global Form is a dynamic npm package, simplifying the process of form creation in Ionic applications. The package supports various form controls such as input fields, checkboxes, date pickers, dropdowns, and more, each equipped with custom validations. Unique to Ionic Global Form is the support for form arrays, which enables efficient grouping of dynamic fields.

In essence, Ionic Global Form enhances your form creation process, supports continuous integration and delivery pipelines, and ensures a better user experience. It's an invaluable addition to any Ionic project.

Easy Real-time Form Updates with Ionic Global Form: No App Store Re-submissions

Ionic Global Form offers a significant advantage by allowing real-time form updates based on backend configurations. You no longer need to manually update the application or push new versions to the app store or play store for each form change. This simplifies the process and saves a lot of development time.

Prerequisites

To use the Ionic Global Form package, make sure your development environment meets the following prerequisites:

  1. Angular: You need to have Angular version 15 or later installed. You can check your version by running ng version in your terminal. If you do not have Angular installed or your version is outdated, follow the instructions provided in the Angular Setup Guide to install or update it.

  2. Ionic: Ionic is a required framework for this package. If you haven't installed Ionic, you can do so by running npm install -g @ionic/cli in your terminal.

  3. Node.js: Make sure you have Node.js installed, as it's required to manage your npm packages. The recommended version is 10.13 or later.

  4. npm: Node Package Manager (npm) is used to install the Ionic Global Form package. If you installed Node.js from the official website, npm is included. You can check your npm version by running npm -v in your terminal.

Once these prerequisites are fulfilled, you are ready to install and use the Ionic Global Form package.

Installation

To use the Dynamic Form Generator in your project, install it via npm:

npm i ionic-global-form --save

Usage

The package is intended to be used with Ionic forms.

Import the necessary types and enums from the package in your Ionic component:

import { ComponentEnum, ValidatorsListEnum, FieldDataInterface, FormDataInterface, ValidationRule } from 'dynamic-form-generator';

Define your form data:

const formData: FormDataInterface[] = [
  // your form fields here
];

Then, in your HTML template, use the form controls provided by the package:

<ion-content [fullscreen]="true">
 <lib-ionic-global-form
  [formData]="formData"
  (formChange)="formChangeFn($event)"
  (formSubmit)="formSubmitFn($event)"
  (openModal)="openModalFn($event)"
  [modalData]="modalData"
></lib-ionic-global-form>
</ion-content>
const formData: FormData[] = [
  {
    // Input Field
    fieldCode: 'inputField',
    fieldName: 'Input Field',
    componentType: ComponentEnum.Input,
    type: 'text',
    placeholder: 'Enter text',
    disabled: false,
    hidden: false,
    fieldValue: '',
    validations: [
      { type: ValidatorsListEnum.REQUIRED },
      { type: ValidatorsListEnum.MAXLENGTH, maxLength: 10 }
    ]
  },
  {
    // Select Field
    fieldCode: 'selectField',
    fieldName: 'Select Field',
    componentType: ComponentEnum.Select,
    dropdownOptions: [
      { value: 'option1', id: '1' },
      { value: 'option2', id: '2' },
      { value: 'option3', id: '3' }
    ],
    disabled: false,
    hidden: false,
    fieldValue: '',
    validations: [{ type: ValidatorsListEnum.REQUIRED }]
  },
  {
    // Multi-Select Field
    fieldCode: 'multiSelectField',
    fieldName: 'Multi-Select Field',
    componentType: ComponentEnum.multiSelect,
    dropdownOptions: [
      { value: 'option1', id: '1' },
      { value: 'option2', id: '2' },
      { value: 'option3', id: '3' }
    ],
    disabled: false,
    hidden: false,
    fieldValue: [],
    validations: [{ type: ValidatorsListEnum.REQUIRED }]
  },
  {
    // Radio Group Field
    fieldCode: 'radioGroupField',
    fieldName: 'Radio Group Field',
    componentType: ComponentEnum.RadioGroup,
    dropdownOptions: [
      { value: 'option1', id: '1' },
      { value: 'option2', id: '2' },
      { value: 'option3', id: '3' }
    ],
    disabled: false,
    hidden: false,
    fieldValue: '',
    validations: [{ type: ValidatorsListEnum.REQUIRED }]
  },
  {
    // Form Array Field
    fieldCode: 'formArrayField',
    fieldName: 'Form Array Field',
    componentType: ComponentEnum.FormArray,
    formArrayFields: [
      {
        // Nested Input Field
        fieldCode: 'nestedInputField',
        fieldName: 'Nested Input Field',
        componentType: ComponentEnum.Input,
        type: 'text',
        placeholder: 'Enter nested text',
        disabled: false,
        hidden: false,
        fieldValue: '',
        validations: [{ type: ValidatorsListEnum.REQUIRED }]
      }
    ],
    formArrayGroupName: 'nestedFields',
    intialFormArrayLength: 1,
    disabled: false,
    hidden: false,
    fieldValue: [],
    validations: []
  },
  {
    // Modal Field
    fieldCode: 'modalField',
    fieldName: 'Modal Field',
    componentType: ComponentEnum.modal,
    modalCode: 'sampleModal',
    modalOptions: {
      isFormArray: false,
      isPerson: false
    },
    disabled: false,
    hidden: false,
    fieldValue: null,
    validations: []
  },
  {
    // Text Area Field
    fieldCode: 'textAreaField',
    fieldName: 'Text Area Field',
    componentType: ComponentEnum.TextArea,
    placeholder: 'Enter text',
    rows: 4,
    disabled: false,
    hidden: false,
    fieldValue: '',
    validations: [{ type: ValidatorsListEnum.REQUIRED }]
  },
  {
    // Connected Selectors Field
    fieldCode: 'connectedSelectorsField',
    fieldName: 'Connected Selectors Field',
    componentType: ComponentEnum.ConnectedSelectors,
    connectedSelectors: [
      {
        fieldCode: 'selector1',
        fieldName: 'Selector 1',
        fieldValue: '',
        placeholder: 'Select option',
        options: [
          { value: 'option1', id: '1', parentId: 'parent1' },
          { value: 'option2', id: '2', parentId: 'parent2' },
          { value: 'option3', id: '3', parentId: 'parent3' }
        ]
      },
      {
        fieldCode: 'selector2',
        fieldName: 'Selector 2',
        fieldValue: '',
        placeholder: 'Select option',
        options: [
          { value: 'option4', id: '4', parentId: 'parent1' },
          { value: 'option5', id: '5', parentId: 'parent2' },
          { value: 'option6', id: '6', parentId: 'parent3' }
        ]
      }
    ],
    disabled: false,
    hidden: false,
    fieldValue: '',
    validations: [{ type: ValidatorsListEnum.REQUIRED }]
  },
  {
    // Date Field
    fieldCode: 'dateField',
    fieldName: 'Date Field',
    componentType: ComponentEnum.Input,
    type: 'date',
    placeholder: 'Select date',
    disabled: false,
    hidden: false,
    fieldValue: '',
    validations: [{ type: ValidatorsListEnum.REQUIRED }]
  }
];

The form controls are rendered dynamically based on the componentType of each field in the form data.

export enum ComponentEnum {
  Input = 'input',
  TextArea = 'textArea',
  Select = 'select',
  multiSelect = 'multiSelect',
  CheckBox = 'checkBox',
  RadioGroup = 'radioGroup',
  DatePicker = 'datePicker',
  ChipField = 'chipField',
  SingleFileUpload = 'singleFileUpload',
  MultipleFileUpload = 'multipleFileUpload',
  ConnectedSelectors = 'connectedSelectors',
  SlideToggle = 'slideToggle',
  FormArray = 'formArray',
  modal = 'modal',
}

ComponentEnum is an enumeration (Enum) that is used to specify the type of each field in the form. This enumeration is used to dynamically render form fields based on the form configuration that you provide.

Here is an explanation of each value in the ComponentEnum:

  • Input: Represents an input field. It's used to get single-line input from the user. You can specify the type of input such as 'text', 'number', 'email', 'date', etc.

  • TextArea: Represents a text area field. It's used to get multiline input from the user.

  • Select: Represents a select field or dropdown. It's used when you want the user to select one option from a list of options.

  • multiSelect: Represents a multi-select field. It's used when you want the user to select multiple options from a list.

  • CheckBox: Represents a checkbox field. It's used when you want the user to select multiple options from a list of checkboxes.

  • RadioGroup: Represents a group of radio buttons. It's used when you want the user to select one option from a list of radio buttons.

  • DatePicker: Represents a date picker field. It's used when you want the user to select a date.

  • ChipField: Represents a chip field. It's used when you want to present a list of options as a group of chips from which the user can select one or more.

  • SingleFileUpload: Represents a single file upload field. It's used when you want the user to upload a single file.

  • MultipleFileUpload: Represents a multiple file upload field. It's used when you want the user to upload multiple files.

  • ConnectedSelectors: Represents connected selectors field. It's used when you want the user to select options from connected dropdowns where the options of one dropdown depend on the selection of the previous one.

  • SlideToggle: Represents a slide toggle or switch field. It's used when you want the user to choose between two options, typically yes/no or on/off.

  • FormArray: Represents a form array field. It's used when you want to group multiple similar fields together. This is helpful when you want to generate a dynamic number of similar fields.

  • modal: Represents a modal field. It's used when you want to open a modal dialog for user input.

In your form data configuration, for each field, you specify the componentType using one of the values from the ComponentEnum. The dynamic form generator then uses this configuration to render the form with the correct types of input fields.

export enum ValidatorsListEnum {
  REQUIRED = 'required',
  EMAIL = 'email',
  PATTERN = 'pattern',
  MIN = 'min',
  MAX = 'max',
  MINLENGTH = 'minLength',
  MAXLENGTH = 'maxLength',
  CUSTOM = 'custom',
}

The ValidationRule type in your TypeScript code is an essential aspect for form validation. It is a union type that allows for different rule structures based on the type of validation you want to apply to a form field. Let's elaborate on this:

Each ValidationRule object has a type property which corresponds to one of the values in the ValidatorsListEnum. This indicates the kind of validation that will be applied to the form field. Below are the different forms a ValidationRule can take:

  1. Required validation: { type: ValidatorsListEnum.REQUIRED } - This rule indicates that the field is required and must be filled in.

  2. Email validation: { type: ValidatorsListEnum.EMAIL } - This rule checks if the field value is a valid email.

  3. Pattern validation: { type: ValidatorsListEnum.PATTERN; pattern: string } - This rule checks if the field value matches the provided regular expression pattern.

  4. Min validation: { type: ValidatorsListEnum.MIN; minValue: number } - This rule ensures the field value is not less than the provided minimum value. It is typically used for number input fields.

  5. Max validation: { type: ValidatorsListEnum.MAX; maxValue: number } - This rule ensures the field value does not exceed the provided maximum value. It is typically used for number input fields.

  6. MinLength validation: { type: ValidatorsListEnum.MINLENGTH; minLength: number } - This rule checks if the length of the field value is not less than the provided minimum length.

  7. MaxLength validation: { type: ValidatorsListEnum.MAXLENGTH; maxLength: number } - This rule checks if the length of the field value does not exceed the provided maximum length.

  8. Custom validation: This is a special case where you can provide a custom validation function. The function should take an AbstractControl object and return a validation error object or null.

    Example:

    type CustomValidationRule = {
      type: ValidatorsListEnum.CUSTOM;
      validate: (control: AbstractControl) => {
        custom: true;
        message: string;
      } | null;
    };

    The custom validation function (validate in the object above) should return an object with custom: true and a message string when validation fails, and null when validation passes. The message will be used to provide the user with information about the validation error.

By providing these various rules, your form fields can be equipped with robust and flexible validation that suits your application's needs.

Contact Information

If you have any queries or feedback regarding the Ionic Global Form package, you can reach out to us through the following channels:

  • Email: email2amitdubey@gmail.com

We're looking forward to hearing from you and are always ready to assist you!

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

0.9.56

6 months ago

0.9.57

6 months ago

0.9.58

6 months ago

0.9.59

6 months ago

0.9.52

7 months ago

0.9.53

7 months ago

0.9.54

7 months ago

0.9.55

7 months ago

0.9.50

7 months ago

0.9.51

7 months ago

0.9.45

7 months ago

0.9.46

7 months ago

0.9.47

7 months ago

0.9.48

7 months ago

0.9.41

7 months ago

0.9.42

7 months ago

0.9.43

7 months ago

0.9.44

7 months ago

0.9.49

7 months ago

0.9.40

7 months ago

0.9.34

7 months ago

0.9.35

7 months ago

0.9.36

7 months ago

0.9.37

7 months ago

0.9.30

7 months ago

0.9.31

7 months ago

0.9.32

7 months ago

0.9.33

7 months ago

0.9.38

7 months ago

0.9.39

7 months ago

0.9.23

7 months ago

0.9.24

7 months ago

0.9.25

7 months ago

0.9.26

7 months ago

0.9.20

7 months ago

0.9.21

7 months ago

0.9.22

7 months ago

0.9.27

7 months ago

0.9.28

7 months ago

0.9.29

7 months ago

0.9.70

6 months ago

0.9.71

6 months ago

0.9.72

6 months ago

0.9.67

6 months ago

0.9.68

6 months ago

0.9.69

6 months ago

0.9.63

6 months ago

0.9.64

6 months ago

0.9.65

6 months ago

0.9.66

6 months ago

0.9.60

6 months ago

0.9.61

6 months ago

0.9.62

6 months ago

0.9.18

7 months ago

0.9.19

7 months ago

0.9.8

9 months ago

0.9.7

9 months ago

0.9.9

9 months ago

0.9.4

9 months ago

0.9.3

9 months ago

0.9.6

9 months ago

0.9.5

9 months ago

0.9.12

9 months ago

0.9.13

9 months ago

0.9.14

9 months ago

0.9.15

9 months ago

0.9.10

9 months ago

0.9.11

9 months ago

0.9.16

9 months ago

0.9.17

9 months ago

0.9.2

9 months ago

0.8.9

10 months ago

0.8.8

10 months ago

0.0.87

12 months ago

0.8.5

11 months ago

0.4.9

11 months ago

0.0.88

12 months ago

0.8.4

11 months ago

0.4.8

11 months ago

0.0.89

12 months ago

0.8.7

11 months ago

0.8.6

11 months ago

0.3.0

11 months ago

0.7.2

11 months ago

0.3.6

11 months ago

0.7.1

11 months ago

0.3.5

11 months ago

0.7.4

11 months ago

0.3.8

11 months ago

0.7.3

11 months ago

0.3.7

11 months ago

0.3.2

11 months ago

0.3.1

11 months ago

0.7.0

11 months ago

0.3.4

11 months ago

0.3.3

11 months ago

0.5.8

11 months ago

0.5.7

11 months ago

0.5.9

11 months ago

0.8.1

11 months ago

0.4.5

11 months ago

0.8.0

11 months ago

0.4.4

11 months ago

0.8.3

11 months ago

0.4.7

11 months ago

0.8.2

11 months ago

0.4.6

11 months ago

0.4.1

11 months ago

0.4.0

11 months ago

0.4.3

11 months ago

0.4.2

11 months ago

0.6.7

11 months ago

0.6.6

11 months ago

0.6.9

11 months ago

0.6.8

11 months ago

0.1.0

12 months ago

0.1.2

12 months ago

0.1.1

12 months ago

0.9.0

10 months ago

0.5.4

11 months ago

0.1.8

12 months ago

0.5.3

11 months ago

0.1.7

12 months ago

0.5.6

11 months ago

0.9.1

10 months ago

0.5.5

11 months ago

0.1.9

12 months ago

0.5.0

11 months ago

0.1.4

12 months ago

0.1.3

12 months ago

0.5.2

11 months ago

0.1.6

12 months ago

0.5.1

11 months ago

0.1.5

12 months ago

0.7.9

11 months ago

0.7.6

11 months ago

0.7.5

11 months ago

0.3.9

11 months ago

0.7.8

11 months ago

0.7.7

11 months ago

0.0.95

12 months ago

0.0.96

12 months ago

0.0.97

12 months ago

0.0.98

12 months ago

0.0.99

12 months ago

0.0.90

12 months ago

0.0.91

12 months ago

0.0.92

12 months ago

0.0.93

12 months ago

0.0.94

12 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.6.3

11 months ago

0.2.7

11 months ago

0.6.2

11 months ago

0.2.6

11 months ago

0.6.5

11 months ago

0.2.9

11 months ago

0.6.4

11 months ago

0.2.8

11 months ago

0.2.3

11 months ago

0.2.2

11 months ago

0.6.1

11 months ago

0.2.5

11 months ago

0.6.0

11 months ago

0.2.4

11 months ago

0.0.86

1 year ago

0.0.85

1 year ago

0.0.84

1 year ago

0.0.83

1 year ago

0.0.82

1 year ago

0.0.81

1 year ago

0.0.80

1 year ago

0.0.79

1 year ago

0.0.78

1 year ago

0.0.77

1 year ago

0.0.76

1 year ago

0.0.75

1 year ago

0.0.74

1 year ago

0.0.73

1 year ago

0.0.72

1 year ago

0.0.71

1 year ago

0.0.70

1 year ago

0.0.69

1 year ago

0.0.68

1 year ago

0.0.67

1 year ago

0.0.66

1 year ago

0.0.65

1 year ago

0.0.64

1 year ago

0.0.63

1 year ago

0.0.62

1 year ago

0.0.61

1 year ago

0.0.60

1 year ago

0.0.59

1 year ago

0.0.57

1 year ago

0.0.56

1 year ago

0.0.55

1 year ago

0.0.54

1 year ago

0.0.53

1 year ago

0.0.52

1 year ago

0.0.51

1 year ago

0.0.50

1 year ago

0.0.49

1 year ago

0.0.48

1 year ago

0.0.47

1 year ago

0.0.46

1 year ago

0.0.45

1 year ago

0.0.44

1 year ago

0.0.43

1 year ago

0.0.42

1 year ago

0.0.41

1 year ago

0.0.40

1 year ago

0.0.39

1 year ago

0.0.38

1 year ago

0.0.37

1 year ago

0.0.36

1 year ago

0.0.35

1 year ago

0.0.34

1 year ago

0.0.33

1 year ago

0.0.32

1 year ago

0.0.31

1 year ago

0.0.30

1 year ago

0.0.29

1 year ago

0.0.28

1 year ago

0.0.27

1 year ago

0.0.26

1 year ago

0.0.25

1 year ago

0.0.24

1 year ago

0.0.23

1 year ago

0.0.22

1 year ago

0.0.21

1 year ago

0.0.20

1 year ago

0.0.19

1 year ago

0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

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.0-watch

1 year ago