How to make choices enabled when it is cloned using jQuery?

Got a select element in a Django template that looks like this:

<select hidden="hidden" id="id_horse{{ field.field.index }}_category" name="horse{{ field.field.index }}_category" class="dropdown" data-settings='{"cutOff":10}'>
    <option value="">--------</option>
    {% for hc in horse_categories %}
            <option value="{{ hc.id }}">{{ hc.horse_category }}</option>
    {% endfor %}
</select>

This file was processed by jQuery easydropdown, and then the result:

<div class="dropdown">
    <span class="old">
        <select hidden="hidden" id="id_horse1_category" name="horse1_category" class="" data-settings="{&quot;cutOff&quot;:10}">
            <option value="">--------</option>

            <option value="1">Jumping</option>

            <option value="2">Endurance</option>

            <option value="3">Dressage</option>

            <option value="4">Polo</option>

            <option value="5">Race</option>

            <option value="6">Arabians</option>

        </select></span><span class="selected">--------</span><span class="carat"></span><div>
            <ul>
                <li class="active">--------</li>
                <li>Jumping</li>
                <li>Endurance</li>
                <li>Dressage</li>
                <li>Polo</li>
                <li>Race</li>
                <li>Arabians</li>
            </ul>
        </div>
</div>

The problem, which is later in the script, I am trying to clone an element containing this select:

var $horse_row = $('.horse-row').last().clone();

and it is actually cloned, but unfortunately the select element in the cloned string is disabled. I know that in Selectpicker AngularJS there is an option 'refresh', which makes it possible to perform such an operation. In easydropdown, there are such things. But maybe there are other workarounds?

+4
source share
1 answer

Could you do something like this:

var $horse_row = $('.horse-row').last().clone();
$horse_row = $($horse_row).find('select').prop('disabled', false);

Hope this helps you.

0
source

Source: https://habr.com/ru/post/1589418/


All Articles