Skip to content

Commit

Permalink
Merge pull request #23 from analogrelay/anurse/mutation-observer
Browse files Browse the repository at this point in the history
add a 'watch' option to wire up a mutation observer
  • Loading branch information
haacked authored Sep 23, 2022
2 parents 2276f03 + 9107194 commit d332cd3
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 34 deletions.
29 changes: 29 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,36 @@ v.isFieldValid(document.getElementById('field'), true, myCallbackFn)
```

## Hidden fields validation

By default validation is skipped for hidden fields. To enable validation for hidden fields validation use:
```ts
v.allowHiddenFields = true;
```

## Monitoring the DOM for changes

If configured, aspnet-client-validation can monitor the DOM for changes using [`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver), if the browser supports it.
As new elements are added/modified, the library will automatically wire up validation directives found.
This can be very useful when using frameworks that modify the DOM, such as [Turbo](http://turbo.hotwired.dev).
To configure this, set the `watch` option to `true` when calling `bootstrap`:

```js
let v = new aspnetValidation.ValidationService();
v.bootstrap({ watch: true });
```

## Logging

There is a rudimentary logging infrastructure in place if you want to get more insight into what the library is doing.
To enable logging, pass an object that implements the `Logger` interface (see below) in to the `ValidationService` constructor.
The `window.console` object satisfies this interface automatically:

```typescript
// The Logger interface, for reference
export interface Logger {
log(message: string, ...args: any[]): void;
}

let v = new aspnetValidation.ValidationService(console);
v.bootstrap();
```
94 changes: 81 additions & 13 deletions dist/aspnet-validation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d332cd3

Please sign in to comment.