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

default AutocompleteModelTemplate choice_template renders with extra spaces #318

Closed
aogier opened this issue Sep 9, 2014 · 2 comments
Closed

Comments

@aogier
Copy link

aogier commented Sep 9, 2014

(maybe related to #255)

Hi, I've got some minor problem using templated classes.

When registering an AutocompleteModelTemplate eg:

autocomplete_light.register(LocalUser,
                            autocomplete_light.AutocompleteModelTemplate,
                            # Just like in ModelAdmin.search_fields
                            search_fields=['^givenName', 'sn', 'uid', 'displayName'],
                            # This will actually html attribute data-placeholder which will set
                            # javascript attribute widget.autocomplete.placeholder.
                            autocomplete_js_attributes={'minimum_characters': 1,
                                                        },
                            )

html response from /autocomplete/ url will be:

<span class="div" data-value="ppiselli">
    Piero Piselli







</span>

the quickest fix is to override template with something similar:

{% load i18n l10n %}
{% load static %}

{% spaceless %}
<span class="div">
    <span data-value="{{ choice.pk|unlocalize }}">{{ choice }}</span>
    {% with choice.get_absolute_url as url %}
        {% if url %}
        <a href="{{ url }}" target="_blank" class="choiceDetail">&rarr;</a>
        {% endif %}
    {% endwith %}

    {% with choice.get_absolute_update_url  as url %}
        {% if url %}
        <a href="{{ url }}" target="_blank" class="choiceUpdate">
            <img src="{% static 'admin/img/icon_changelink.gif' %}" />
        </a>
        {% endif %}
    {% endwith %}
</span>
{% endspaceless %}

spaceless will do the rest, producing a cleaner:

<span class="div"><span data-value="ppiselli">Piero Piselli</span></span>

This produce better output while maintaining good code readability, and does not break existing javascript

Many thanks for this package, it's great !

ciao,
ale

@jpic
Copy link
Member

jpic commented Apr 7, 2015

Thanks for the kind words ;)

Pull requests are welcome !

@jpic jpic closed this as completed Apr 7, 2015
@blueyed blueyed reopened this Apr 7, 2015
jpic added a commit that referenced this issue Jun 1, 2015
jpic added a commit that referenced this issue Jun 1, 2015
@jpic
Copy link
Member

jpic commented Jun 1, 2015

Closing in favor of PR #437

@jpic jpic closed this as completed Jun 1, 2015
jpic added a commit that referenced this issue Jun 2, 2015
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

3 participants