<p>You could use <a href="https://select2.org/getting-started/basic-usage" rel="nofollow noreferrer">Select2</a> to search in a select field </p>

<pre><code>$(document).ready(function() {
    $('.my-custom-awesome-select-class').select2();
});
</code></pre>

<p>All you need to do is to include the js file via asset bundle or register it in your view directly and execute the JS code </p>

CC BY-SA 4.0
2018-06-29T14:05:02.273Z
2018-06-29T14:05:02.273Z
Robin Schambach
<p>I created a custom FieldType that gathers data from 2 different Models. I was able to successfully display it as a Drop Down. My problem now is that there are tooo many records on my array and I would like to have a search instead similar to what craft already has implemented on the Tags Field.</p>

<p>My current template is:</p>

<pre><code>    {%- set class = [
    'select',
    (class is defined ? class : null)
    ]|filter|join(' ') %}

    {% set selectedValue = (value is defined ? value : null)  %}

    &lt;div class="{{ class }}"&gt;
        &lt;select {%- if name is defined %} name="{{ name }}"{% endif %}&gt;
    {% if value is not null %}
    {% set selectedValue = value.id %}
    {% endif %}
    {% else %}
    &lt;option value="0" &gt; &lt;/option&gt;
    {% endif %}

    {% for test in tests %}
    {% set optionValue = test.id %}
    &lt;option value="{{test.id}}" {% if optionValue == selectedValue %} selected{% endif %}&gt;Test - {{ test.name }}: {{ test.price }}&lt;/option&gt;
            {% endfor %}
        &lt;/select&gt;
    &lt;/div&gt;
</code></pre>

<p>Any way I can make it similar to the <code>craft/app/templates/_components/fieldtypes/Tags/input.html</code></p>

CC BY-SA 4.0
2018-06-29T13:58:15.473Z
Would it be an option to use an external library like https://select2.org/dropdown ? Otherwise you'll need to create a custom script for it
Robin Schambach
CC BY-SA 4.0
2018-06-29T13:59:51.727Z
That would be amazing. not sure how to implement. any advice?
juanmrad
<templating><custom-fieldtype>
Input Tags Template for my Custom FieldType
# Input Tags Template for my Custom FieldType

(Asked by: username_0 on 2018-06-29)

I created a custom FieldType that gathers data from 2 different Models. I was able to successfully display it as a Drop Down. My problem now is that there are tooo many records on my array and I would like to have a search instead similar to what craft already has implemented on the Tags Field.
My current template is:
    {%- set class = [
    'select',
    (class is defined ? class : null)
    ]|filter|join(' ') %}

    {% set selectedValue = (value is defined ? value : null)  %}

    
        
    {% if value is not null %}
    {% set selectedValue = value.id %}
    {% endif %}
    {% else %}
     
    {% endif %}

    {% for test in tests %}
    {% set optionValue = test.id %}
    Test - {{ test.name }}: {{ test.price }}
            {% endfor %}
        
    

Any way I can make it similar to the craft/app/templates/_components/fieldtypes/Tags/input.html

**Tags:** templating, custom-fieldtype
> **Comments:**
> **username_1**: Would it be an option to use an external library like https://select2.org/dropdown ? Otherwise you'll need to create a custom script for it  
> **username_0**: That would be amazing. not sure how to implement. any advice?  

---

## 1 answers

### Answer by username_1 on 2018-06-29. Score: 2 | Accepted answer

You could use Select2 to search in a select field 
$(document).ready(function() {
    $('.my-custom-awesome-select-class').select2();
});

All you need to do is to include the js file via asset bundle or register it in your view directly and execute the JS code


---

