Skip to content

[Autocomplete] Distinct autocomplete field from normal field in templates #608

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

Merged

Conversation

AlexandreGerault
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
Tickets Fix #581
License MIT

As discussed in the corresponding issue, it should allow to easily distinct autocomplete fields from non autocomplete fields with a variable added to the view.

Before, I used to write this:

{% block choice_widget %}
    {% set attr = attr|merge({'class': 'my-input-css-class'}) %}

    {# Condition simplified, let's assume the stimulus controller can only be autocomplete for the example #}
    {% if attr['data-controller'] is not defined %}
    <select name="{{ full_name }}" {{ block('widget_attributes') }}>
        {% for choice in choices %}
            <option value="{{ choice.value }}" {% if choice.value == value %}selected{% endif %}>{{ choice.label }}</option>
        {% endfor %}
    </select>
    {% else %}
        {{ parent() }}
    {% endif %}
{% endblock %}

With this, it should be able to become as below:

{% block choice_widget %}
    {% set attr = attr|merge({'class': 'my-input-css-class'}) %}

    {% if not autocomplete %}
    <select name="{{ full_name }}" {{ block('widget_attributes') }}>
        {% for choice in choices %}
            <option value="{{ choice.value }}" {% if choice.value == value %}selected{% endif %}>{{ choice.label }}</option>
        {% endfor %}
    </select>
    {% else %}
        {{ parent() }}
    {% endif %}
{% endblock %}

@AlexandreGerault AlexandreGerault force-pushed the feature/autocomplete_view_variable branch from 0d1813d to 0c5c7f0 Compare December 14, 2022 16:19
@weaverryan weaverryan force-pushed the feature/autocomplete_view_variable branch from 50ae8d1 to a386722 Compare December 15, 2022 16:30
@weaverryan
Copy link
Member

Thanks Alexandre!

@weaverryan weaverryan merged commit eeecf18 into symfony:2.x Dec 15, 2022
@AlexandreGerault AlexandreGerault deleted the feature/autocomplete_view_variable branch December 15, 2022 16:34
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

Successfully merging this pull request may close these issues.

[Autocomplete] Distinct autocomplete field from normal field in templates
2 participants