-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
Selectize-field misbehaving #1461
Comments
This fixed the first instance of this issue. I fixed for myself like this: {% extends "forms/field.html.twig" %}
{% block global_attributes %}
{% set user_generated_options = [] %}
{% if value is defined %}
{% if value is not iterable %}
{% set delimiter = (field.selectize.delimiter is defined ? field.selectize.delimiter : ',') %}
{% set value = value|split(delimiter) %}
{% endif %}
{% for item in value %}
{% set user_generated_options = user_generated_options|merge({( field.selectize.options|length + loop.index): {'text': item, 'value': item}})%}
{% endfor %}
{% endif %}
{% set all_options = field.selectize.options|merge(user_generated_options) %}
data-grav-selectize="{{ (field.selectize is defined ? field.selectize|merge({'create': true})|merge({'items':value})|merge({'options' : all_options}) : {'create': true})|json_encode()|e('html_attr') }}"
{{ parent() }}
{% endblock %}
{% block input_attributes %}
type="text"
{{ parent() }}
{% endblock %} |
Did this work for you too @OleVik ? PR would be great if so :) |
My tests work fine with the initial reversal, I've yet to understand why the reversal was implemented:
|
It was reverted because it was causing other issues. |
The recent change to the Selectize-field broke its ability to merge existing items, which had been implemented previously.
In a specific scenario, such as overriding taxonomies:
Using this post.md:
Leaving out
|merge({'items':value})
causes only the first item to be loaded, the subsequent values are removed when the DOM finishes loading:Whereas adding it back in to selectize.html.twig, from:
data-grav-selectize="{{ (field.selectize is defined ? field.selectize|merge({'create': true}) : {'create': true})|json_encode()|e('html_attr') }}"
to
data-grav-selectize="{{ (field.selectize is defined ? field.selectize|merge({'create': true})|merge({'items':value}) : {'create': true})|json_encode()|e('html_attr') }}"
makes it work again:
I submit this as an issue rather than a PR to also ask about the use of
selectize: options
rather than justoptions:
. The latter is more in line with blueprints generally. The logic of #1236 seems sound, but why was the reversal necessary? Seemingly for selectize-plugins, but how does that differ from the existing implementation?The text was updated successfully, but these errors were encountered: