Skip to content

Commit

Permalink
Merge pull request #10 from skttl/docs
Browse files Browse the repository at this point in the history
Add docs changes
  • Loading branch information
haacked authored Nov 18, 2021
2 parents f13bfdd + 017c8f2 commit 6d3cf8f
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ v.bootstrap();

```js
require('core-js');
const aspnetValidation = require('aspnet-validation');
const aspnetValidation = require('aspnet-client-validation');

let v = new aspnetValidation.ValidationService();
v.bootstrap();
Expand All @@ -56,7 +56,7 @@ v.bootstrap();

```ts
import 'ts-polyfill';
import { ValidationService } from 'aspnet-validation';
import { ValidationService } from 'aspnet-client-validation';

let v = new ValidationService();
v.bootstrap();
Expand Down Expand Up @@ -126,7 +126,7 @@ public class ClassicMovieAttribute : ValidationAttribute, IClientModelValidator
### Client Code

```ts
import { ValidationService } from 'aspnet-validation';
import { ValidationService } from 'aspnet-client-validation';
let v = new ValidationService();

v.addProvider('classicmovie', (value, element, params) => {
Expand Down Expand Up @@ -170,8 +170,52 @@ v.addProvider('io', (value, element, params) => {
## Subscribing to Client Form Validation Event

```ts
cost form = document.getElementById('form');
const form = document.getElementById('form');
form.addEventListener('validation', function (e) {
/* Check if form is valid here. */
});
```

## Programatically validate a form

```ts
v.validateForm(document.getElementById('form'));
```

## Checking form validity

```ts
v.isValid(document.getElementById('form'))
```

By default it will try to validate the form, before returning whether the form is valid. This can be disabled by setting the `prevalidate` parameter like so:

```ts
v.isValid(document.getElementById('form'), false)
```

You can also supply a callback function to be run after the check.

```ts
v.isValid(document.getElementById('form'), true, myCallbackFn)
```

## Checking field validity

Similar to checking a forms validity, you can check individual fields too.

```ts
v.isFieldValid(document.getElementById('field'))
```

By default it will try to validate the form surrounding the field, before returning whether the field is valid. This can be disabled by setting the `prevalidate` parameter like so:

```ts
v.isFieldValid(document.getElementById('field'), false)
```

You can also supply a callback function to be run after the check.

```ts
v.isFieldValid(document.getElementById('field'), true, myCallbackFn)
```

0 comments on commit 6d3cf8f

Please sign in to comment.