Skip to content

How to prevent the validation to retrigger here? I want to clear form values on success #138

@TheDayIsMyEnemy

Description

@TheDayIsMyEnemy

`function clearValidationMessages(form) {
// Remove text in all validation message spans
form.querySelectorAll('[data-valmsg-for]').forEach((span) => {
span.textContent = '';
span.classList.remove('field-validation-error');
span.classList.add('field-validation-valid');
});

// Optional: remove validation error classes from inputs
form.querySelectorAll('[data-val][name]').forEach((input) => {
input.value = '';
input.classList.remove('input-validation-error');
input.classList.add('input-validation-valid');
});
}

const services = serviceCollection.init();
// console.log(services);

const validationService = new aspnetValidation.ValidationService();
validationService.bootstrap();
console.log(validationService);

const newsletterForms = document.querySelectorAll('.newsletter form');
// console.log(newsletterForms);
for (let form of newsletterForms) {
form.addEventListener('submit', async (e) => {
e.preventDefault();
const form = e.target;
const isValid = await validationService.isValid(form);
if (isValid) {
const subbscribed = await services.newsletterService.subscribe(form);
if (subbscribed) {
// form.reset();
clearValidationMessages(form);
}
}
});
}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions