Skip to content

Commit

Permalink
Update to 0.9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
haacked committed Mar 18, 2024
1 parent 5008fe3 commit 05ee048
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
31 changes: 28 additions & 3 deletions dist/aspnet-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ var MvcValidationProviders = /** @class */ (function () {
var payload = encodedParams.join('&');
return new Promise(function (ok, reject) {
var request = new XMLHttpRequest();
if (params.type === 'Post') {
if (params.type && params.type.toLowerCase() === 'post') {
var postData = new FormData();
for (var fieldName in fields) {
postData.append(fieldName, fields[fieldName]);
Expand Down Expand Up @@ -508,6 +508,9 @@ var ValidationService = /** @class */ (function () {
* @param callback Receives true or false indicating validity after all validation is complete.
*/
this.validateForm = function (form, callback) {
if (!(form instanceof HTMLFormElement)) {
throw new Error('validateForm() can only be called on <form> elements');
}
var formUID = _this.getElementUID(form);
var formValidationEvent = _this.formEvents[formUID];
if (formValidationEvent) {
Expand Down Expand Up @@ -544,6 +547,9 @@ var ValidationService = /** @class */ (function () {
* @param submitEvent The `SubmitEvent`.
*/
this.handleValidated = function (form, success, submitEvent) {
if (!(form instanceof HTMLFormElement)) {
throw new Error('handleValidated() can only be called on <form> elements');
}
if (success) {
if (submitEvent) {
_this.submitValidForm(form, submitEvent);
Expand All @@ -563,11 +569,15 @@ var ValidationService = /** @class */ (function () {
* @param submitEvent The `SubmitEvent`.
*/
this.submitValidForm = function (form, submitEvent) {
if (!(form instanceof HTMLFormElement)) {
throw new Error('submitValidForm() can only be called on <form> elements');
}
var newEvent = new SubmitEvent('submit', submitEvent);
if (form.dispatchEvent(newEvent)) {
// Because the submitter is not propagated when calling
// form.submit(), we recreate it here.
var submitter = submitEvent.submitter;
var initialFormAction = form.action;
if (submitter) {
var name_1 = submitter.getAttribute('name');
// If name is null, a submit button is not submitted.
Expand All @@ -578,15 +588,27 @@ var ValidationService = /** @class */ (function () {
submitterInput.value = submitter.getAttribute('value');
form.appendChild(submitterInput);
}
var formAction = submitter.getAttribute('formaction');
if (formAction) {
form.action = formAction;
}
}
try {
form.submit();
}
finally {
form.action = initialFormAction;
}
form.submit();
}
};
/**
* Focuses the first invalid element within the provided form
* @param form
*/
this.focusFirstInvalid = function (form) {
if (!(form instanceof HTMLFormElement)) {
throw new Error('focusFirstInvalid() can only be called on <form> elements');
}
var formUID = _this.getElementUID(form);
var formInputUIDs = _this.formInputs[formUID];
var invalidFormInputUIDs = formInputUIDs.filter(function (uid) { return _this.summary[uid]; });
Expand All @@ -607,6 +629,9 @@ var ValidationService = /** @class */ (function () {
*/
this.isValid = function (form, prevalidate, callback) {
if (prevalidate === void 0) { prevalidate = true; }
if (!(form instanceof HTMLFormElement)) {
throw new Error('isValid() can only be called on <form> elements');
}
if (prevalidate) {
_this.validateForm(form, callback);
}
Expand Down Expand Up @@ -660,7 +685,7 @@ var ValidationService = /** @class */ (function () {
*/
this.ValidationSummaryCssClassName = "validation-summary-errors";
/**
* Override CSS class name for valid validation summary. Default: 'field-validation-valid'
* Override CSS class name for valid validation summary. Default: 'validation-summary-valid'
*/
this.ValidationSummaryValidCssClassName = "validation-summary-valid";
this.logger = logger || nullLogger;
Expand Down
Loading

0 comments on commit 05ee048

Please sign in to comment.