Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to add a "loading" gif to the input? #244

Closed
yliharma opened this issue Jan 27, 2014 · 28 comments
Closed

Is there a way to add a "loading" gif to the input? #244

yliharma opened this issue Jan 27, 2014 · 28 comments

Comments

@yliharma
Copy link

It would be useful to show a "loading" gif to the user into the input text while he's searching, otherwise it seems the request didn't find anything even if it's still running...
Sorry if this already exists but I couldn't find it (I'm using version 2).

@jpic
Copy link
Member

jpic commented Jan 27, 2014

That's a great idea. What gif should we use ? Something from ajaxload.info ?

@yliharma
Copy link
Author

Yes, that sort of thing! I think there are plenty of them (free, I hope...) on the web to use.

@jpic
Copy link
Member

jpic commented Jan 27, 2014

You can use $.ajaxStart(), but it would nice to provide that feature out of the box BTW, it's a really good idea.

We could trigger an event in Autocomplete.makeXhr() and another one in Autocomplete.fetchComplete. That might be overkill, we could just add a class .xhr-pending to this.input in those functions and define the input's background in style.css for .xhr-pending.

@jpic jpic closed this as completed in a231c0e Jan 27, 2014
@jpic
Copy link
Member

jpic commented Jan 27, 2014

Released in 2.0.0a13, thanks for your feedback !

@yliharma
Copy link
Author

Wow, immediate answer!! Thank you! 👍

@jpic
Copy link
Member

jpic commented Jan 28, 2014

Try 2.0.0a14 BTW, 2.0.0a13 misses the default images.

On Tue, Jan 28, 2014 at 10:39 AM, yliharma [email protected] wrote:

Wow, immediate answer!! Thank you! [image: 👍]


Reply to this email directly or view it on GitHubhttps://github.com//issues/244#issuecomment-33463338
.

http://yourlabs.org http://blog.yourlabs.org
Customer is king - Le client est roi - El cliente es rey.

@yliharma
Copy link
Author

Yes I saw that and installed the git repo using
pip install -e git+https://github.com/yourlabs/django-autocomplete-light.git#egg=autocomplete_light

@jpic
Copy link
Member

jpic commented Jan 28, 2014

How do you like it ?​ Does it work for you ?

@yliharma
Copy link
Author

It works, it's exactly what I needed!
But I noticed changes in the css (the input is smaller) and it doesn't seem to use the choice_template I specified in a class which inherits from AutocompleteGenericTemplate...
I've uninstallaed the app, deleted all pyc files and tried to reinstall it this time using:
pip install 'django-autocomplete-light>=2.0.0a14'
but nothing changed. Any clue?

@jpic
Copy link
Member

jpic commented Jan 28, 2014

I did try to make it a bit more consistent with other fields.

Could you open the autocomplete url directly and check the HTML and ensure that choice template isn't used ?

Could you paste your autocomplete_light_registry.py ?

@yliharma
Copy link
Author

Sorry, the template works, it was my fault...those admin pages are all the same and I was looking to a non generic autocomplete 😄
As for the input style I agree that probably it's better for it to be similar to the others...though I liked it more before!
Thank you again!

@jpic
Copy link
Member

jpic commented Jan 28, 2014

Yep me too. Maybe we could offer several styles and let the user activate
the wanted style with input_attrs={'class': 'some-style'} what do you think
?

On Tue, Jan 28, 2014 at 12:43 PM, yliharma [email protected] wrote:

Sorry, the template works, it was my fault...those admin pages are all the
same and I was looking to a non generic autocomplete [image: 😄]
As for the input style I agree that probably it's better for it to be
similar to the others...though I liked it more before!
Thank you again!


Reply to this email directly or view it on GitHubhttps://github.com//issues/244#issuecomment-33471332
.

http://yourlabs.org http://blog.yourlabs.org
Customer is king - Le client est roi - El cliente es rey.

@yliharma
Copy link
Author

Isn't that already possible specifying the attrs attribute for the widget? Django provides a way to do things like that:
name = forms.CharField(widget=forms.TextInput(attrs={'class':'special'}))
https://docs.djangoproject.com/en/1.6/ref/forms/widgets/#styling-widget-instances
Of course it involves writing all the code for the form...

@jpic
Copy link
Member

jpic commented Jan 28, 2014

Yes my bad, we call it attrs as well now.​ I don't recommend that you
override the widget like that:
http://django-autocomplete-light.readthedocs.org/en/v2/faq.html#model-field-s-help-text-and-verbose-name-are-lost-when-overriding-the-widget

However, doing as stated in the faq was broken and I just fixed it xD

@jpic
Copy link
Member

jpic commented Jan 28, 2014

If you upgrade to 2.0.0a15, you can use the modern style again. For example:

class YourForm(autocomplete_light.ModelForm):
    class Meta:
        model = YourModel
        widgets = {'your_field': autocomplete_light.SomeWidget(widget_attrs={'class': 'modern-style'})}

Don't forget to replace autocomplete_light.SomeWidget by the right widget (probably either ChoiceWidget or MultipleChoiceWidget).

Note that there is attrs to set input attributes, and widget_attrs to set attributes on the widget container (a span.autocomplete-light-widget by default). NOT the same ;)

@yliharma
Copy link
Author

Something breaks if I add the widget definition
widgets = {'film': autocomplete_light.ChoiceWidget(widget_attrs={'class': 'modern-style'})}
in the form's Meta class: whenever I save I get an AttributeError 'tuple' object has no attribute 'model'. Tomorrow I'll dig into it, now it's too late!

@jpic
Copy link
Member

jpic commented Jan 28, 2014

Ok, paste the full form definition when you can !

On Tue, Jan 28, 2014 at 6:04 PM, yliharma [email protected] wrote:

Something breaks if I add the widget definition
widgets = {'film': autocomplete_light.ChoiceWidget(widget_attrs={'class':
'modern-style'})}
in the form's Meta class: whenever I save I get an AttributeError 'tuple'
object has no attribute 'model'. Tomorrow I'll dig into it, now it's too
late!


Reply to this email directly or view it on GitHubhttps://github.com//issues/244#issuecomment-33499118
.

http://yourlabs.org http://blog.yourlabs.org
Customer is king - Le client est roi - El cliente es rey.

@yliharma
Copy link
Author

class BoxofficeFilmForm(autocomplete_light.ModelForm):
    class Meta:
        model = BoxofficeFilm
        widgets = {'film': autocomplete_light.ChoiceWidget(widget_attrs={'class': 'modern-style'})}

And this is the relevant part of the traceback:
traceback

@jpic
Copy link
Member

jpic commented Jan 29, 2014

Could you switch to copy/paste mode and paste the full traceback please ? I can't see what function caused this ;D

Also, are you sure that you're using the latest version of django-autocomplete-light ?

Also, did you check that model with ContentType 42 and PK 2152 exists in the database ?

@yliharma
Copy link
Author

Request Method: POST
Request URL: http://127.0.0.1:8000/admin/film/boxoffice/add/

Django Version: 1.6.1
Python Version: 2.7.3

Traceback:
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  432.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  198.             return view(request, *args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  29.             return bound_func(*args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  25.                 return func(self, *args2, **kwargs2)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
  339.                 return func(*args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
  1130.             if all_valid(formsets) and form_validated:
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/formsets.py" in all_valid
  415.         if not formset.is_valid():
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/formsets.py" in is_valid
  292.         err = self.errors
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/formsets.py" in errors
  267.             self.full_clean()
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/formsets.py" in full_clean
  315.             self._errors.append(form.errors)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/forms.py" in errors
  121.             self.full_clean()
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/forms.py" in full_clean
  273.         self._clean_fields()
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/forms.py" in _clean_fields
  288.                     value = field.clean(value)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/fields.py" in clean
  148.         value = self.to_python(value)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/models.py" in to_python
  1136.         except (ValueError, self.queryset.model.DoesNotExist):

Exception Type: AttributeError at /admin/film/boxoffice/add/
Exception Value: 'tuple' object has no attribute 'model'

I tried executing again:

pip install -U -e git+https://github.com/yourlabs/django-autocomplete-light.git#egg=autocomplete_light

and obtained:

Creating /home/paola/.virtualenvs/movie/lib/python2.7/site-packages/django-autocomplete-light.egg-link (link to .)
    django-autocomplete-light 1.4.13 is already the active version in easy-install.pth

Yes the instance of model with ContentType 47 exists (after all it was autocomplete_light which retrieved it from the database...)

@jpic
Copy link
Member

jpic commented Jan 29, 2014

django-autocomplete-light 1.4.13 is already the active version in easy-install.pth

This means you're not on v2.

You should try to uninstall and re-install again.

If you want to install from the git repo in development mode then:

pip install -e git+https://github.com/yourlabs/django-autocomplete-light.git@v2#egg=autocomplete_light

Note the difference: @v2

Then, to update:

cd env/src/autocomplete_light
git pull origin v2
pip install -e .

I have tested everything I could think of in today's commits and couldn't reproduce the problem, maybe using the right autocomplete-light version will help ?

@yliharma
Copy link
Author

Same error, same traceback....

Request Method: POST
Request URL: http://127.0.0.1:8000/admin/film/boxoffice/add/

Django Version: 1.6.1
Python Version: 2.7.3


Traceback:
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  432.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  198.             return view(request, *args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  29.             return bound_func(*args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  25.                 return func(self, *args2, **kwargs2)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
  339.                 return func(*args, **kwargs)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
  1130.             if all_valid(formsets) and form_validated:
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/formsets.py" in all_valid
  415.         if not formset.is_valid():
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/formsets.py" in is_valid
  292.         err = self.errors
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/formsets.py" in errors
  267.             self.full_clean()
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/formsets.py" in full_clean
  315.             self._errors.append(form.errors)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/forms.py" in errors
  121.             self.full_clean()
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/forms.py" in full_clean
  273.         self._clean_fields()
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/forms.py" in _clean_fields
  288.                     value = field.clean(value)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/fields.py" in clean
  148.         value = self.to_python(value)
File "/home/paola/.virtualenvs/movie/local/lib/python2.7/site-packages/django/forms/models.py" in to_python
  1136.         except (ValueError, self.queryset.model.DoesNotExist):

Exception Type: AttributeError at /admin/film/boxoffice/add/
Exception Value: 'tuple' object has no attribute 'model'
(movie)paola-ubuntu:~$ pip install -e git+https://github.com/yourlabs/django-autocomplete-light.git@v2#egg=autocomplete_light
Obtaining autocomplete-light from git+https://github.com/yourlabs/django-autocomplete-light.git@v2#egg=autocomplete_light
  Cloning https://github.com/yourlabs/django-autocomplete-light.git (to v2) to ./.virtualenvs/movie/src/autocomplete-light
  Running setup.py egg_info for package autocomplete-light
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/hr/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/it/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/es/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/cs/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/pt_BR/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/fr/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/ru/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/pl/LC_MESSAGES

Requirement already satisfied (use --upgrade to upgrade): six>=1.4 in ./.virtualenvs/movie/lib/python2.7/site-packages (from autocomplete-light)
Installing collected packages: autocomplete-light
  Running setup.py develop for autocomplete-light
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/hr/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/it/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/es/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/cs/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/pt_BR/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/fr/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/ru/LC_MESSAGES
    processing file django.po in /home/paola/.virtualenvs/movie/src/autocomplete-light/autocomplete_light/locale/pl/LC_MESSAGES

    Creating /home/paola/.virtualenvs/movie/lib/python2.7/site-packages/django-autocomplete-light.egg-link (link to .)
    Adding django-autocomplete-light 2.0.0a15 to easy-install.pth file

    Installed /home/paola/.virtualenvs/movie/src/autocomplete-light
Successfully installed autocomplete-light
Cleaning up...

@yliharma
Copy link
Author

It doesn't seem to be able to split the string containing content type id and object id.
If you look at the screenshot I posted earlier, you will see that "key" is "id" and "value" is "47-2152"

@jpic
Copy link
Member

jpic commented Jan 29, 2014

Could you paste models and autocomplete_light_registry please ?

@yliharma
Copy link
Author

class FilmAutocomplete(autocomplete_light.AutocompleteModelBase):
    search_fields = ['^name', '^original']
    order_by = ['name']
    choice_html_format = u'''
        <span class="block" data-value="%s">%s <a href="%s" target="_blank" class="choice-detail">&rarr;</a></span>
    '''

    def choice_html(self, choice):
        return self.choice_html_format % (self.choice_value(choice), self.choice_label(choice.get_full_name()),
            choice.get_absolute_url())

autocomplete_light.register(models.Film, FilmAutocomplete)

This is the inline model for the form I posted above:

class BoxofficeFilm(models.Model):
    boxoffice = models.ForeignKey(Boxoffice)
    film = models.ForeignKey(Film)
    weekend = models.BigIntegerField("incasso")
    theaters = models.IntegerField("sale", blank=True, null=True)
    average = models.IntegerField("media", blank=True, null=True)
    total = models.BigIntegerField("totale", blank=True, null=True)
    status = models.SmallIntegerField("tendenza", blank=True, null=True, 
        choices=BOXOFFICE_STATUS_CHOICES)

The Film and Boxoffice models are too big to post 😄

@jpic
Copy link
Member

jpic commented Jan 29, 2014

I see, you have not specified the autocomplete name, it should be:

autocomplete_light.ChoiceWidget('FilmAutocomplete', widget_attrs={'class': 'modern-style'})}

It's using a generic autocomplete by default. I might find a way to fix that but that's not garanteed.

@jpic
Copy link
Member

jpic commented Jan 29, 2014

I did mislead you, sorry !

@yliharma
Copy link
Author

😄 No problem, it happens! Thank you, now it works as expected!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants