Skip to content

Commit

Permalink
Merge pull request #110 from haacked/gh100-fix-remove
Browse files Browse the repository at this point in the history
Fix removing validation + Undebounce
  • Loading branch information
haacked authored May 6, 2024
2 parents 062c843 + 2f5020d commit fd1e5a6
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 225 deletions.
21 changes: 21 additions & 0 deletions Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
</div>

<input type="submit" asp-for="SubmitButton" class="btn" value="Save" />
<button type="button" class="btn" data-action="remove">Disable Validation</button>
</form>
</fieldset>

Expand All @@ -98,6 +99,7 @@
</div>

<button type="submit" class="btn">Save</button>
<button type="button" class="btn" data-action="remove">Disable Validation</button>
</form>
</fieldset>

Expand All @@ -110,11 +112,15 @@
<span asp-validation-for="Input.SomeRequiredField"></span>
</div>
<button type="submit" class="btn">Save</button>
<button type="button" class="btn" data-action="remove">Disable Validation</button>
</form>
</fieldset>

@section scripts {
<script>
const service = new aspnetValidation.ValidationService(console);
service.bootstrap();
document.addEventListener('DOMContentLoaded', function () {
console.log('Listening to Form 4')
document.getElementById('prevent-default').addEventListener('submit', function (e) {
Expand All @@ -123,8 +129,23 @@
alert(new URLSearchParams(data));
});
});
document.querySelectorAll('[data-action="remove"]').forEach(function (removeButton) {
removeButton.addEventListener('click', function (removeClick) {
if (removeButton.validationRemoved) {
service.scan(removeButton.form);
removeButton.textContent = 'Enable Validation';
removeButton.validationRemoved = false;
} else {
service.remove(removeButton.form);
removeButton.textContent = 'Disable Validation';
removeButton.validationRemoved = true;
}
});
});
</script>
}

<fieldset>
<legend>Form 4 (<code>preventDefault()</code>)</legend>
<form method="post" id="prevent-default">
Expand Down
269 changes: 161 additions & 108 deletions dist/aspnet-validation.js

Large diffs are not rendered by default.

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.

4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aspnet-client-validation",
"version": "0.9.6",
"version": "0.10.0",
"description": "Enables ASP.NET MVC client-side validation, without jQuery!",
"main": "dist/aspnet-validation.js",
"style": "dist/aspnet-validation.css",
Expand Down
Loading

0 comments on commit fd1e5a6

Please sign in to comment.