Reputation: 908
I have a simple registration page in my Django web application. Once a user signs up, I am able to query my database and see if the username is already in use, if it is, I display a simple ValidationError
.
My problem is I can't figure out how to remove the error after a few seconds. I'm pretty good with Python but haven't found any luck, the only thing I can find is [this][1] outdated article from 2010 that gives me code that doesn't work anymore.
Bellow is my function for recognizing if the username is already in use and my HTML file. Thank you to everyone who helps!
def clean(self):
cleaned_data=super().clean()
if User.objects.filter(username=cleaned_data["username"]).exists():
raise ValidationError("This username is taken, please try another one")
Upvotes: 0
Views: 707
Reputation: 32284
This is a very basic script that will remove all errors on the page after 3 seconds. Add it to the bottom of your HTML so that it is run after everything has rendered
<script>
setTimeout(function() {
let errors = document.getElementsByClassName('errorlist');
while(errors.length > 0) {
errors[0].parentNode.removeChild(errors[0]);
}
}, 3000);
</script>
Upvotes: 1