What I want to do is that when you have more than 300 digits you can't touch the "Bloob" button or something like that. What is on the left is a counter with javascript. The models is this
class Post(models.Model):
timestamp = models.DateTimeField(default=timezone.now)
content = models.TextField(max_length=300)
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='posts')
This is the PostForm
class PostForm(forms.ModelForm):
content = forms.CharField(widget=forms.Textarea(attrs={
'class': 'form-control w-100',
'id': 'contentsBox',
'rows': '3',
'placeholder': '¿Qué está pasando?'
}))
CodePudding user response:
The changing of bloob button from active to inactive gets Donne on your web page. With each keystroke in the text you will want to run a little javascript test that sets the bloob button state. Once the post is received by the server you will want to test that the size of the text is valid. It is possible to craft a malicious post request with invalid parameters. Test on the page as a courtesy to the user, test on the server for safety. Besides a bloob button going inactive you could reveal a message on the screen that the maximum text size was exceeded and perhaps a character count field that automatically updates, all with javascript.
CodePudding user response:
idk if this is what you want exactly.
but below is how to limit the number of characters in a textbox in html.
<input type="text" maxlength="10">
hope this helps! :)
below is a link to a w3schools example aswell