0.0.12 • Published 4 months ago

angular-json-forms v0.0.12

Weekly downloads
-
License
-
Repository
github
Last release
4 months ago

Adding custom validator function

To add a custom validator function to a field you can add an object to the validators array like below. AbstractControl is the AbstractControl type from Angular and will be passed to this validator function.

To add a custom synchronous validator to a field add it to the synValidators object on the form schema like shown below.

  syncValidators = {
    someGroup: {
      someField: [
        {
          name: 'someValidatorName',
          validator: (control: AbstractControl) => {
             if (control.value !== 'Some Value') {
                return { someValidatorName: 'Input needs to equal Some Value'}
              }
              return null;
          }
        }
      ]
    }
  }

Here is an example of adding an async validator.

  asyncValidators = {
    someGroup: {
      someField: [
        {
          name: 'someValidatorName',
          validator: (control: AbstractControl) => {
             return of(true).pipe(map(res => ({asyncError: 'This is an async error'})))
          }
        }
      ]
    }
  }
0.0.11

4 months ago

0.0.12

4 months ago

0.0.10

4 months ago

0.0.9

4 months ago

0.0.8

4 months ago

0.0.5

4 months ago

0.0.4

4 months ago

0.0.7

4 months ago

0.0.6

4 months ago

0.0.1

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.0

5 years ago