Skip to content

Commit d332cd3

Browse files
authored
Merge pull request #23 from analogrelay/anurse/mutation-observer
add a 'watch' option to wire up a mutation observer
2 parents 2276f03 + 9107194 commit d332cd3

File tree

12 files changed

+242
-34
lines changed

12 files changed

+242
-34
lines changed

README.MD

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,36 @@ v.isFieldValid(document.getElementById('field'), true, myCallbackFn)
221221
```
222222

223223
## Hidden fields validation
224+
224225
By default validation is skipped for hidden fields. To enable validation for hidden fields validation use:
225226
```ts
226227
v.allowHiddenFields = true;
228+
```
229+
230+
## Monitoring the DOM for changes
231+
232+
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.
233+
As new elements are added/modified, the library will automatically wire up validation directives found.
234+
This can be very useful when using frameworks that modify the DOM, such as [Turbo](http://turbo.hotwired.dev).
235+
To configure this, set the `watch` option to `true` when calling `bootstrap`:
236+
237+
```js
238+
let v = new aspnetValidation.ValidationService();
239+
v.bootstrap({ watch: true });
240+
```
241+
242+
## Logging
243+
244+
There is a rudimentary logging infrastructure in place if you want to get more insight into what the library is doing.
245+
To enable logging, pass an object that implements the `Logger` interface (see below) in to the `ValidationService` constructor.
246+
The `window.console` object satisfies this interface automatically:
247+
248+
```typescript
249+
// The Logger interface, for reference
250+
export interface Logger {
251+
log(message: string, ...args: any[]): void;
252+
}
253+
254+
let v = new aspnetValidation.ValidationService(console);
255+
v.bootstrap();
227256
```

dist/aspnet-validation.js

Lines changed: 81 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)