-1

i've tried using django-autocomplete-light with following the docs guide, and in the end i cannot input string to search the data, here the picture

enter image description here

I can't input string to search data. heres my code:

views.py

    from django.shortcuts import render
    from .models import *
    from .forms import PendaftaranForm
    from dal import autocomplete

    # Create your views here.
    class DesaAutocomplete(autocomplete.Select2QuerySetView):
        def get_queryset(self):
            # Don't forget to filter out results depending on the visitor !
            #if not self.request.user.is_authenticated:
                #return Country.objects.none()

            qs = Desa.objects.all()

            if self.q:
                qs = qs.filter(name__istartswith=self.q)

            return qs

models.py

class Desa(models.Model):
    nama = models.CharField(max_length=30)
    kecamatan = models.ForeignKey(Kecamatan, null=True, blank=True, on_delete=models.CASCADE)

    def __str__(self):
        return self.nama

urls.py

from django.urls import path
from django.conf.urls import url
from . import views

urlpatterns = [
    path('', views.index, name='index'),

    url(
        r'^desa-autocomplete/$',
        views.DesaAutocomplete.as_view(),
        name='desa-autocomplete',
    ),
    
]

forms.py

from django import forms
from .models import *
from tempus_dominus.widgets import DatePicker
from dal import autocomplete

class PendaftaranForm(forms.ModelForm):
    class Meta:
        model=Pendaftaran
        fields= (
            'tanggal_pendaftaran',
            'nama',
            'desa',
            'kecamatan',
            'mutasi',
            'jumlah',
            'keterangan',
            'tanggal_selesai',
            )
        widgets =  {
            'tanggal_pendaftaran':DatePicker(
                attrs={
                'append': 'fa fa-calendar',
                'icon_toggle': True,
                }
            ),

            'nama':forms.TextInput(
                attrs={
                    'class':'form-control',
                }
            ),

            'desa':autocomplete.ModelSelect2(
                url='desa-autocomplete',
                attrs={
                    'class':'form-control',
                }
            ),
            ...

how can i input the string to search? is there anything wrong with my code? thank for your help.

triefauzan
  • 25
  • 4
  • You should just be able to type in the field. Seems like a CSS issue. Inspect the element in your browser and try to see what's wrong? – SaeX Feb 18 '21 at 20:23
  • yess its a css issue and i've found the problem, i'm using bootstrap modal and thats the problem. – triefauzan Feb 19 '21 at 08:21
  • @SaeX can you tell me problem? i too have same problem. – ShiBil PK Jan 31 '23 at 15:26
  • @ShiBilPK: I do not understand your question "can you tell me problem" - the answer to the topic/question is to inspect CSS as duplicate/conflicting declarations might be used. – SaeX Feb 01 '23 at 08:35
  • @triefauzan how you fixed it? – ShiBil PK Feb 07 '23 at 06:02

1 Answers1

0

Ensure no conflicting CSS is used on the element, like bootstrap modal.

SaeX
  • 17,240
  • 16
  • 77
  • 97