mercredi 22 juin 2022

checkbox django return all false

My checkbox always return False value my model

ho_so_giu=models.BooleanField(default=False)

my form

 ho_so_giu = forms.BooleanField(label="Hồ sơ giữ", widget=forms.CheckboxInput(attrs={'class': 'form-check-input', 'id': 'ho_so_giu_text', 'name': 'ho_so_giu_text',}),required=False)

in my html template

<div class="form-check form-switch">
     
     <label class="form-check-label" for="ho_so_giu_text">Hồ sơ giữ</label>
</div>

in my view,

print(form.cleaned_data["ho_so_giu"])  ## return False
print(request.POST.get("ho_so_giu"))   ## return None
print(request.GET.get("ho_so_giu"))    ## return None

if I try to print ho_so_giu_text it show errors

    print(form.cleaned_data["ho_so_giu_text"])
KeyError: 'ho_so_giu_text'

I am using ajax to return my value from code

ho_so_giu =$('#ho_so_giu_text').val() //return on

Thanks for reading anh help me




Aucun commentaire:

Enregistrer un commentaire