From e1fc53e430ac4bc85020c4717db93b670121bcfb Mon Sep 17 00:00:00 2001 From: Just Me Date: Mon, 5 Feb 2024 19:02:10 +0200 Subject: [PATCH] f js --- .../javascripts/rails_admin/custom/grade-groups.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/assets/javascripts/rails_admin/custom/grade-groups.js b/app/assets/javascripts/rails_admin/custom/grade-groups.js index f8390900..2ba27a6b 100644 --- a/app/assets/javascripts/rails_admin/custom/grade-groups.js +++ b/app/assets/javascripts/rails_admin/custom/grade-groups.js @@ -24,13 +24,23 @@ $('[data-component="grade-groups"]').each(function () { newGroupOption.value = grades.join(','); newGroupOption.text = options.map(o => o.text).join(', '); groupSelect.appendChild(newGroupOption); + options.forEach(o => o.remove()); }); $('button[data-action="move-to-grades"]').on('click', function () { const options = Array.from(groupSelect.selectedOptions); const groups = options.map(o => o.value.split(',').map(grade => parseInt(grade))); + const texts = options.map(o => o.text.split(',')); const newValue = value.filter(a => !groups.some(b => arrayEq(a, b))); setValue(newValue); options.forEach(o => o.remove()); + groups.forEach((grades, i) => { + grades.forEach((grade, j) => { + const newGradeOption = document.createElement('option'); + newGradeOption.value = grade; + newGradeOption.text = texts[i][j]; + gradeSelect.appendChild(newGradeOption); + }); + }); }); });