Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Extend selectize field

Started by Muut Archive 9 years ago · 2 replies · 1159 views
9 years ago

Hi guys, I try to extend the selectize form field, i need to add a simple class to a selectize-input item or directly in the option of the select but if i try to do that in the "forms/fields/select/select.html.twig"

TWIG
<option 
                        {% if key == value or (field.multiple and selected in value) %}
                            selected="selected"
                        {% endif %}
                        class="error"
                        value="{{ item_value }}"
                        >
                        {% if grav.twig.twig.filters['tu'] is defined %}
                        {{ text|tu|raw }},{% else %},{{ text|t|raw }},{% endif %}
                        </option>

I always have this result in the html

TXT
<option value="20701AA005" selected="selected">20701AA005</option>

the class was erased!

I need to show a different backgroud color based on condition, i've alredy write the condition check but i'm unable to add this class.
Anyone have suggestions?
Thanks

9 years ago

Are you adding forms/fields/select/select.html.twig in your theme?

Also, this is a frontend form, right? Or are you trying to change an Admin field?

9 years ago

hi, I'm sorry for my late reply..
I'm creating a custom administration field, so I've created a plug-in. Need to verify the existence of a page and to communicate the outcome of the operation by changing the background color of the selectize saved value.
I managed to do so by adding an custom attribute to the select field (data-itemstatus="") that contain a json object with the response of the check condition and after i process it via javascript to add a custom class to the selectize item.. It works whitout problem but i'don't understand why i can't do that simply by add a class to the option. I think the problem is in selectize.js?&quest;... If I understand correctly it create the selectize item based to the selected option and can't keep the class attribute.
PS: In my plug-in i have that path admin hemes\grav emplates\forms\fields and here I put my custom select.html.twig

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1323 9 years ago
Archive · by Muut Archive, 9 years ago
2 920 9 years ago
Archive · by Muut Archive, 9 years ago
2 4048 9 years ago
Archive · by Muut Archive, 9 years ago
1 2924 9 years ago
Archive · by Muut Archive, 9 years ago
3 1106 9 years ago