django-htmx-tutorial icon indicating copy to clipboard operation
django-htmx-tutorial copied to clipboard

add modal

Open jorgeav527 opened this issue 3 years ago • 3 comments

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 avatar Jan 01 '22 13:01 jorgeav527

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.

rg3915 avatar Jan 04 '22 03:01 rg3915

  1. Add a book with the title "mesmo titulo"

Screenshot from 2022-01-04 11-32-45

  1. ele cola no top da tabela, tudo bem ate aqui

Screenshot from 2022-01-04 11-32-54

  1. agora eu coloco o mesmo título do livro

Screenshot from 2022-01-04 11-33-25

  1. o formulario tem algum tipo de erro mais ele nao se mostra no mesmo formulario ele é jogado como mais um item da tabela

Screenshot from 2022-01-04 11-33-36

  • 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 avatar Jan 04 '22 17:01 jorgeav527

@jorgeav527 você tem duas opções:

  1. remova o unique=True
  2. insira o messages no seu template https://docs.djangoproject.com/en/4.0/ref/contrib/messages/#displaying-messages

rg3915 avatar Jan 07 '22 02:01 rg3915