Skip to content

Commit

Permalink
Build latest
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlbyk committed Aug 13, 2023
1 parent 421626b commit 658e43f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
22 changes: 19 additions & 3 deletions dist/aspnet-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,14 @@ var ValidationService = /** @class */ (function () {
var fieldUID = _this.getElementUID(field);
return _this.summary[fieldUID] === undefined;
};
/**
* Options for this instance of @type {ValidationService}.
*/
this.options = {
root: document.body,
watch: false,
addNoValidate: true,
};
/**
* Override CSS class name for input validation error. Default: 'input-validation-error'
*/
Expand Down Expand Up @@ -833,6 +841,13 @@ var ValidationService = /** @class */ (function () {
var add = (this.formInputs[formUID].indexOf(inputUID) === -1);
if (add) {
this.formInputs[formUID].push(inputUID);
if (this.options.addNoValidate) {
this.logger.log('Setting novalidate on form', form);
form.setAttribute('novalidate', 'novalidate');
}
else {
this.logger.log('Not setting novalidate on form', form);
}
}
else {
this.logger.log("Form input for UID '%s' is already tracked", inputUID);
Expand Down Expand Up @@ -1172,17 +1187,18 @@ var ValidationService = /** @class */ (function () {
/**
* Load default validation providers and scans the entire document when ready.
* @param options.watch If set to true, a MutationObserver will be used to continuously watch for new elements that provide validation directives.
* @param options.addNoValidate If set to true (the default), a novalidate attribute will be added to the containing form in validate elemets.
*/
ValidationService.prototype.bootstrap = function (options) {
var _this = this;
options = options || {};
Object.assign(this.options, options);
this.addMvcProviders();
var document = window.document;
var root = options.root || document.body;
var root = this.options.root;
var init = function () {
_this.scan(root);
// Watch for further mutations after initial scan
if (options.watch) {
if (_this.options.watch) {
_this.watch(root);
}
};
Expand Down
2 changes: 1 addition & 1 deletion dist/aspnet-validation.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aspnet-validation.min.js.map

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ export declare class MvcValidationProviders {
*/
remote: ValidationProvider;
}
/**
* Configuration for @type {ValidationService}.
*/
export interface ValidationServiceOptions {
watch: boolean;
root: ParentNode;
addNoValidate: boolean;
}
/**
* Responsible for managing the DOM elements and running the validation providers.
*/
Expand Down Expand Up @@ -290,14 +298,16 @@ export declare class ValidationService {
* @param removeClass Class to remove
*/
private swapClasses;
/**
* Options for this instance of @type {ValidationService}.
*/
private options;
/**
* Load default validation providers and scans the entire document when ready.
* @param options.watch If set to true, a MutationObserver will be used to continuously watch for new elements that provide validation directives.
* @param options.addNoValidate If set to true (the default), a novalidate attribute will be added to the containing form in validate elemets.
*/
bootstrap(options?: {
watch?: boolean;
root?: ParentNode;
}): void;
bootstrap(options?: Partial<ValidationServiceOptions>): void;
/**
* Scans the provided root element for any validation directives and attaches behavior to them.
*/
Expand Down

0 comments on commit 658e43f

Please sign in to comment.