harvesthq / chosen

Deprecated - Chosen is a library for making long, unwieldy select boxes more friendly.
http://harvesthq.github.io/chosen/
Other
21.85k stars 4.1k forks source link

Передача значений в селект #3123

Closed 515 closed 3 years ago

515 commented 3 years ago

Good afternoon. I try to pass the values without reloading the page, but the ability to select parameters stops working

My html

<div id="qd__">
                <div id="qd_" class="non d-block">
                    <label class="pt-3 pb-1" for="">Вопросы</label><br>
                    <select name="" id="question_multiple_chosen" data-placeholder="Список выбранных вопросов" class="chosen-select col-md-12" multiple="" tabindex="">
                        @foreach($questions as $question)
                        <option value="{{$question->id}}">{{$question->question}}</option>
                        @endforeach
                    </select>
                </div>
            </div>

My js

function selectMultipleBilder(arr) {
    htmlSelect = '<ul class = \"chosen-results\">';
    arr.forEach(function(item) {
        htmlSelect += '<li class=\"active-result\" data-option-array-index=\"' + item.id + '\">' + item.question + '</li>';
    });
    htmlSelect += '</ul>';
            document.getElementById('question_multiple_chosen_chosen').children[1].innerHTML = htmlSelect;
}

If I try to just replace the code the element breaks up

function selectMultipleBilder(arr) {
    htmlSelect = '<label class="pt-3 pb-1" for="">Вопросы</label><br><select name="" id="question_multiple_chosen" data-placeholder="Список выбранных вопросов" class="chosen-select col-md-12" multiple="" tabindex="">';
    arr.forEach(function(item) {
        htmlSelect += '<option value="' + item.id + '">' + item.question + '</option>';
    });
    htmlSelect += '</select>';
            document.getElementById('qd_').innerHTML = htmlSelect;      
}

In the documentation, I did not find how to reload the element itself. Help please.

tjschuck commented 3 years ago

In the documentation, I did not find how to reload the element itself. Help please.

After updating the underlying select, you can call $("#your_chosen_select_id").trigger("chosen:updated"); to rebuild Chosen with the current state of the select.

Documented here: https://harvesthq.github.io/chosen/#change-update-events

515 commented 3 years ago

This doesn't work, or I'm passing the new values incorrectly. In any case, the answer did not help

tjschuck commented 3 years ago

What browser, browser version, OS, and OS version are you using? And what version of Chosen? If not the latest version, does it still happen on the latest version?

Additionally, please link to a publicly accessible page (or a Fiddle) that shows the issue so we can attempt to reproduce.

515 commented 3 years ago

I have solved my question, thank you. Response by link https://stackoverflow.com/questions/68895345/updating-the-jquery-chosen-selection-list-without-reloading-the-page/68905537?noredirect=1#comment121776494_68905537

вт, 24 авг. 2021 г. в 17:52, T.J. Schuck @.***>:

What browser, browser version, OS, and OS version are you using? And what version of Chosen? If not the latest version, does it still happen on the latest version https://github.com/harvesthq/chosen/releases?

Additionally, please link to a publicly accessible page (or a Fiddle http://jsfiddle.net) that shows the issue so we can attempt to reproduce.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/harvesthq/chosen/issues/3123#issuecomment-904712510, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4UGEOHYVZPEK5KAYAH4YDT6OWZRANCNFSM5CU2TZHA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

-- dfjdhfjhdjf

С уважением,

███─███─████──────████──█─████ █────█──█──█──────█────██─█ ███──█──█─────────████──█─████ ──█──█──█──█─────────█──█────█ ███─███─████─████─████──█─████

Whatsapp Viber Telegram: 8 (900) 133-38-08 <+7+(900)+13+33+808>

Skype: Heretic_515 (в режиме чата)

ICQ: 606017777 http://www.icq.com/whitepages/cmd.php?uin=UIN&action=message

mail: @. @.?subject=Вопрос+по+HTML>, @. @.?subject=Вопрос+по+HTML>

tjschuck commented 3 years ago

Awesome, thanks for following up, and I'm glad you found a solution!