django-htmx-tutorial
django-htmx-tutorial copied to clipboard
add modal
in the add modal form and the update modal: when I submit and invalid data or I add errors by a modelForm to be rendered, the errors are popping up as a new item in the table
What I find is thist... https://stackoverflow.com/questions/69256529/form-is-not-bound-in-django
in the add modal form and the update modal: when I submit and invalid data or I add errors by a modelForm to be rendered, the errors are popping up as a new item in the table
What I find is thist... https://stackoverflow.com/questions/69256529/form-is-not-bound-in-django
@jorgeav527 your data is_valid
? What errors?
Show your code and your error, please.
- Add a book with the title "mesmo titulo"
- ele cola no top da tabela, tudo bem ate aqui
- agora eu coloco o mesmo título do livro
- o formulario tem algum tipo de erro mais ele nao se mostra no mesmo formulario ele é jogado como mais um item da tabela
- agora voce esta validando a data mediante no models.py
title = models.CharField('título', max_length=100, **unique=True**)
- eu quero validar no memo forms.py
class BookForm(forms.ModelForm):
required_css_class = 'required'
class Meta:
model = Book
fields = ('title', 'author')
def clean_ruc(self):
title = self.cleaned_data.get("title")
qs = Book.objects.filter(title__exact=title)
if qs.exists():
self.add_error('ruc', 'El titulo esta ya existe.')
return title
por outro lado quero mostrar os erros e a docummentaçao django fala que os messagens "from django.contrib import messages" somente funciona cuando a pagina completa é renderizada, no modal vc tem algum jeito para mostrar os erros mesmo seja mediante unique=true ou a def clean function
@jorgeav527 você tem duas opções:
- remova o
unique=True
- insira o messages no seu template https://docs.djangoproject.com/en/4.0/ref/contrib/messages/#displaying-messages