0.0.12 • Published 1 year ago

angular-json-forms v0.0.12

Weekly downloads
-
License
-
Repository
github
Last release
1 year 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

1 year ago

0.0.12

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.1

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.0

6 years ago