Choices.js Как удалить конкретную опцию из раскрывающегося списка?Jquery

Программирование на jquery
Ответить
Anonymous
 Choices.js Как удалить конкретную опцию из раскрывающегося списка?

Сообщение Anonymous »


After delete operation I want to delete the options from my dropdown list. But unfortunately seem like choices doesn't have the option to delete it. Is there any work around ?


Изображение


The 2023 record is already deleted from my database and i used choices to remove the active selected items already. But the issue is the 2023 record is still existed in my dropdown options. How can i delete it from the options ?Tq

JS script:
// Initialize Choices outside of your event handlers var choicesInstance = new Choices('#choices-single-default'); //Delete Year Function $('#deleteYear').click(function() { var selectedYear = $('#choices-single-default').val(); var roomId = window.location.pathname.split('/').pop(); if (selectedYear && selectedYear !== 'null' && selectedYear !== '') { // Use SweetAlert for confirmation Swal.fire({ title: 'Are you sure?', text: 'You will not be able to recover this record!', icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, delete it!', cancelButtonText: 'No, cancel!' }).then((result) => { if (result.isConfirmed) { // Perform AJAX request to delete the record $.ajax({ url: '/delete-monthly-energy/' + roomId + '/' + selectedYear, type: 'POST', dataType: 'json', data: { _token: $('meta[name="csrf-token"]').attr('content'), year: selectedYear }, success: function(data) { Swal.fire( 'Deleted!', 'Your record has been deleted.', 'success' ); choicesInstance.removeActiveItems(selectedYear); choicesInstance.setChoiceByValue(""); clearInputFields(); handleYearChange(); }, error: function(xhr, status, error) { Swal.fire( 'Error!', 'There was a problem deleting the record: ' + error, 'error' ); } }); } else if (result.dismiss === Swal.DismissReason.cancel) { Swal.fire( 'Cancelled', 'Nothing is deleted', 'error' ); } }); } else { Swal.fire( 'No year selected', 'Please select a year to delete.', 'info' ); } });

Источник: https://stackoverflow.com/questions/780 ... m-dropdown
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Jquery»